1,页面自动适应屏幕分辨率
以下脚本以客户端屏幕分辨率1024为基准,对屏幕分辨率小于1024的客户端的页面,进行了宽度和样式表的调整,使页面具有了部分“智能化”,提高了用户界面的友好度。
- <script>
- var ad_tl_width=930;
- var ad_tl_height=80;
- var ad_full_height=300;
- var screenwidth=1024;
- if(screen.width < screenwidth)
- {
- ad_tl_width=760;
- ad_tl_height=80;
- ad_full_height=245;
- document.write (’<style type=”text/css”>.ch_right{display=”none”;}</style>’);
- document.write (’<style type=”text/css”>.linktable{width: 760px;;}</style>’);
- }
- else
- {
- document.write (’<style type=”text/css”>.linktable{width: 930px;}</style>’);
- }
- </script>
2,定制调用 Flash 函数
调用 Flash 动画在网页编程中是经常用到的。你是不是每调用一个 swf 文件都写一长串差不多重复的代码呢?
问题还在于,如果 flash 组件本版升级了,你是不是还要把每段代码都打开修改那个冗长的classid=”…………”呢?
其实,只要写一个 javascript 函数,在调用 flash 动画文件的时候,写几行代码就可以了。
函数如下:
- <script>
- function ad_flash(u,w,h)
- {
- document.write (”<object classid=’clsid:D27CDB6E-AE6D-11cf-96B8-444553540000′
- codebase=’http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0′
- width=”+w+” height=”+h+”><param name=’movie’ value=”+u+”><param name=’quality’ value=’high’><param
- name=’wmode’ value=’opaque’><embed src=”+u+” quality=’high’
- pluginspage=’http://www.macromedia.com/go/getflashplayer’ type=’application/x-shockwave-flash’
- param name=’wmode’ value=’opaque’ width=”+w+” height=”+h+”></embed></object>”);
- }
- </script>
- 调用示例:
- <script>ad_flash(”why100000.com.swf”,768,80);</script>
3,定制调用图片函数
和以上定制调用 Flash 函数类似,只要传递连接、图片文件路径,图片的宽度、高度,就可以定义一个图片连接同样避免了大段的重复代码。
函数如下:
- <script>
- function ad_pic(a,s,w,h)
- {
- document.write (”<a href=”+a+ ” target=_blank><img src=”+s+” border=0 width=”+w+”
- height=”+h+”></a>”);
- }
- </script>
- 调用示例:
- <script>ad_pic
- (”http://www.why100000.com”,”http://www.why100000.com/p_w_picpaths/why100000.com.gif”,768,80);</script>