1,页面自动适应屏幕分辨率
以下脚本以客户端屏幕分辨率1024为基准,对屏幕分辨率小于1024的客户端的页面,进行了宽度和样式表的调整,使页面具有了部分“智能化”,提高了用户界面的友好度。

  1. <script>  
  2. var ad_tl_width=930;  
  3. var ad_tl_height=80;  
  4. var ad_full_height=300;  
  5. var screenwidth=1024;  
  6. if(screen.width < screenwidth)  
  7. {  
  8.   ad_tl_width=760;  
  9.   ad_tl_height=80;  
  10.   ad_full_height=245;  
  11.   document.write (’<style type=”text/css”>.ch_right{display=”none”;}</style>’);  
  12.   document.write (’<style type=”text/css”>.linktable{width: 760px;;}</style>’);  
  13. }  
  14. else 
  15. {  
  16.   document.write (’<style type=”text/css”>.linktable{width: 930px;}</style>’);  
  17. }  
  18. </script>  
  19.  

 

2,定制调用 Flash 函数
调用 Flash 动画在网页编程中是经常用到的。你是不是每调用一个 swf 文件都写一长串差不多重复的代码呢?
问题还在于,如果 flash 组件本版升级了,你是不是还要把每段代码都打开修改那个冗长的classid=”…………”呢?
其实,只要写一个 javascript 函数,在调用 flash 动画文件的时候,写几行代码就可以了。
函数如下:
 

  1. <script>  
  2. function ad_flash(u,w,h)  
  3. {  
  4. document.write (”<object classid=’clsid:D27CDB6E-AE6D-11cf-96B8-444553540000′  
  5.  
  6. codebase=’http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0′  
  7.  
  8. width=”+w+” height=”+h+”><param name=’movie’ value=”+u+”><param name=’quality’ value=’high’><param  
  9.  
  10. name=’wmode’ value=’opaque’><embed src=”+u+” quality=’high’  
  11.  
  12. pluginspage=’http://www.macromedia.com/go/getflashplayer’ type=’application/x-shockwave-flash’  
  13.  
  14. param name=’wmode’ value=’opaque’ width=”+w+” height=”+h+”></embed></object>”);  
  15. }  
  16. </script>  
  17. 调用示例:  
  18. <script>ad_flash(”why100000.com.swf”,768,80);</script>  

 

3,定制调用图片函数
和以上定制调用 Flash 函数类似,只要传递连接、图片文件路径,图片的宽度、高度,就可以定义一个图片连接同样避免了大段的重复代码。
函数如下:
 

  1. <script>  
  2. function ad_pic(a,s,w,h)  
  3. {  
  4.   document.write (”<a href=”+a+ ” target=_blank><img src=”+s+” border=0 width=”+w+”  
  5.  
  6. height=”+h+”></a>”);  
  7. }  
  8. </script>  
  9. 调用示例:  
  10. <script>ad_pic  
  11.  
  12. (”http://www.why100000.com”,”http://www.why100000.com/p_w_picpaths/why100000.com.gif”,768,80);</script>  
  13.