Warning: curl_exec() has been disabled for security reasons in /pub/host/sunboyu/sunboyu/www/wp-includes/http.php on line 1022
JavaScript跨浏览器兼容代码 » Blog Archive 一个程序猿 孙小一,孙小二,PHP,MYSQL,LINUX,APACHE,原创技术,扯淡

JavaScript跨浏览器兼容代码

作者 : admin 于 2008-08-03 22:58:07 标签: , ,
2008
08-3

方法1:检测浏览器关键字

  1. function __navigator()
  2. {
  3.     this.value = false;   //返回值  ie 0 firefox 1 other 2
  4. this.useragent =  navigator['userAgent'];
  5. if(this.useragent.indexOf('MSIE')>0)
  6. {
  7.     this.value = 0;
  8. }
  9. else if(this.useragent.indexOf('Firefox')>0)
  10. {
  11.     this.value = 1;
  12. }
  13. else
  14. {
  15.     this.value = 2;
  16. }
  17. }

方法2:

  1. if(document.all)
  2.   ie
  3. else
  4.   other

方法3:

  1. <!--[if IE]>
  2.     js for ie
  3. <![endif]-->
  4. <!--[if !IE]>
  5.     js for !ie
  6. <![endif]-->

方法4:

  1. /*@cc_on
  2.   @if(@_jscript)
  3.   is for ie
  4.   @else*/
  5.   js for !ie
  6. /*@end
  7.   @*/

发表评论




XHTML:你可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(若看不到验证码,请重新加载页面。)