JavaScript跨浏览器兼容代码
作者 : admin 于 2008年08月03日, 22:58:07
2008
08-3
08-3
方法1:检测浏览器关键字
- function __navigator()
- {
- this.value = false; //返回值 ie 0 firefox 1 other 2
- this.useragent = navigator['userAgent'];
- if(this.useragent.indexOf('MSIE')>0)
- {
- this.value = 0;
- }
- else if(this.useragent.indexOf('Firefox')>0)
- {
- this.value = 1;
- }
- else
- {
- this.value = 2;
- }
- }
方法2:
- if(document.all)
- ie
- else
- other
方法3:
- <!--[if IE]>
- js for ie
- <![endif]-->
- <!--[if !IE]>
- js for !ie
- <![endif]-->
方法4:
- /*@cc_on
- @if(@_jscript)
- is for ie
- @else*/
- js for !ie
- /*@end
- @*/