一个与浏览器有关的脚本 ,也是大家从事WEb前端编程常见的编程技巧,就是判断浏览器的版本,如果发现版本不符合你的设计要求,就给出提示升级浏览器,这样你的网页会更有体验。只有使用IE6浏览器才会看到效果。


  
  1. <html>  
  2. <head>  
  3. <title>判断IE版本并给出提示升级浏览器</title>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  5. </head>  
  6. <style type="text/CSS">  
  7. #ie6-warning{  
  8. rgb(255,255,225) url("") no-repeat scroll 3px;  < /span>
  9. position:absolute;  
  10. top:0;  
  11. left:0;  
  12. font-size:50px;  
  13. color:#333;  
  14. width:100%;  
  15. height:500px;  
  16. padding: 2px 15px 2px 23px;  
  17. text-align:left;  
  18. line-height: 100px;  
  19. text-align: center;  
  20. z-index: 9999;  
  21. }  
  22. #ie6-warning a {  
  23. text-decoration:none;  
  24. color:green;  
  25. font-size: 40px;  
  26. }  
  27. </style>  
  28. <body>  
  29. <!--[if lte IE 6]>  
  30. <div id="ie6-warning">您正在使用 Internet Explorer 6,<br />在本页面的显示效果可能有差异。<br />建议您升级到 <a href="http://www.microsoft.com/china/windows/internet-explorer/" target="_blank">Internet Explorer 8</a> <br />或以下浏览器: <br /><a href="http://www.mozillaonline.com/">Firefox</a> / <a href="http://www.google.com/chrome/?hl=zh-CN">Chrome</a> / <a href="http://www.apple.com.cn/safari/">Safari</a> / <a href="http://www.operachina.com/">Opera</a>  
  31. </div>  
  32. <script type="text/javascript">  
  33. function position_fixed(el, eltop, elleft){  
  34. // check if this is IE6  
  35. if(!window.XMLHttpRequest)  
  36. window.onscroll = function(){  
  37. el.style.top = (document.documentElement.scrollTop + eltop)+"px";  
  38. el.style.left = (document.documentElement.scrollLeft + elleft)+"px";  
  39. }  
  40. else el.style.position = "fixed";  
  41. }  
  42. position_fixed(document.getElementById("ie6-warning"),0, 0);  
  43. </script>  
  44. <![endif]-->  
  45. </body>  
  46. </html>