//  firefox
if ( window.sidebar && "object" == typeof( window.sidebar ) && "function" == typeof( window.sidebar.addPanel ) ) 
{


//  ie
else if ( document.all && "object" == typeof( window.external ) )
 {

}

js用来区别IE与其他浏览器及IE6-8之间的方法。
1、document.all 
2、!!window.ActiveXObject;
使用方法如下:
if (document.all){ alert(”IE浏览器”); }else{ alert(”非IE浏览器”); }
if (!!window.ActiveXObject){ alert(”IE浏览器”); }else{ alert(”非IE浏览器”); }
下面是区别IE6、IE7、IE8之间的方法:
var isIE=!!window.ActiveXObject; 
var isIE6=isIE&&!window.XMLHttpRequest; 
var isIE8=isIE&&!!document.documentMode; 
var isIE7=isIE&&!isIE6&&!isIE8; 
if (isIE)

      if (isIE6)
      { 
           alert(”ie6″); 
       }
      else if (isIE8)
       {
           alert(”ie8″); 
       }else if (isIE7)
      { 
           alert(”ie7″); 
      } 
}
首先我们确保这个浏览器为IE的情况下,进行了在一次的检测,如果你对此有怀疑,可以测试一下。
我这里就直接使用在判断中了,你也可以将他们先进行声明成变量进行使用。据说火狐以后也会加入document.all这个方法,所以建议使用第二种方法,应该会安全一些。
用navigator.userAgent.indexOf()来区分多浏览器,代码示例如下:
<html> 
<head> 
<title>TAG index Web</title> 
</head> 
<body> 
<script type="text/javascript"> 
document.write('浏览器判別:');
// 包含「Opera」文字列 
if(navigator.userAgent.indexOf("Opera") != -1) 

     document.write('您的浏览器是Opera吧?'); 

// 包含「MSIE」文字列 
else if(navigator.userAgent.indexOf("MSIE") != -1) 

     document.write('您的浏览器是Internet Explorer吧?'); 

// 包含「Firefox」文字列 
else if(navigator.userAgent.indexOf("Firefox") != -1) 

    document.write('您的浏览器时Firefox吧?'); 
}
// 包含「Netscape」文字列 
else if(navigator.userAgent.indexOf("Netscape") != -1)

    document.write('您的浏览器时Netscape吧?'); 

// 包含「Safari」文字列 
else if(navigator.userAgent.indexOf("Safari") != -1) 

     document.write('您的浏览器时Safari 吧?'); 

else{ 
   document.write('无法识别的浏览器。'); 

document.write(''); 
</script> 
</body> 
</html>

参考:http://www.cnblogs.com/zizaisuixin/archive/2012/06/07/2540314.html

//js广告定位和回到顶部设计

<html>

<title>js广告定位和回到顶部设计</title>

<body>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<h1><span>1111</span></h1>
<img src="img/2.png" id="imgid" style="position: absolute;" />
</body>
<script>
//js广告定位和回到顶部设计
var imgobj=document.getElementById("imgid");
var imgw=imgobj.clientWidth;
var winw=document.documentElement.clientWidth;
var imgleft=winw-imgw;
imgobj.style.left=imgleft+"px";
imgobj.style.top=0+"px";
window.onscroll=function(){
// var sh=document.documentElement.scrollTop; ie写法
// var sh=document.body.scrollTop; //谷歌写法
// imgobj.style.top=sh+100+"px";

//判断浏览器方法一:
// if(!!window.ActiveXObject){
// var sh=document.documentElement.scrollTop;
// imgobj.style.top=sh+100+"px";
// }else{
// var sh=document.body.scrollTop;
// imgobj.style.top=sh+100+"px";
// }

//判断浏览器方法二:
if(document.all){
var sh=document.documentElement.scrollTop;
imgobj.style.top=sh+100+"px";
}else{
var sh=document.body.scrollTop;
imgobj.style.top=sh+100+"px";
}
}
</script>

</html>

js 判断是什么类型浏览器的更多相关文章

  1. JS判断访问设备(userAgent)加载不同页面 JS判断客户端操作系统类型(platform)

    //平台.设备和操作系统 var system ={ win : false, mac : false, xll : false }; //检测平台 var p = navigator.platfor ...

  2. js判断是否为手机浏览器

    JS判断手机浏览器 判断原理: JavaScript是前端开发的主要语言,我们可以通过 编写JavaScript程序来判断浏览器的类型及版本.JavaScript判断浏览器类型一般有两种办法,一种是根 ...

  3. js判断是否是ie浏览器且给出ie版本

    之前懒得写判断ie版本js,因为网上关于这方面的代码太多了,所以从网上拷贝了一个,放到项目上才发现由于时效性的问题,代码不生效.就自己写一个吧. 怎么去看浏览器的内核等信息 ---- js的全局对象w ...

  4. js判断是哪种浏览器和阻止页面加载

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  5. JS判断设备的类型

    利用JS判断浏览器的用户代理,从而获得设备类型.利用这个方法可以获得用户的设备是移动设备还是PC设备.     JS代码如下:       function browerType() {       ...

  6. js 判断访问终端类型

    // 判断访问终端类型 var browser = { versions: function() { var u = navigator.userAgent, app = navigator.appV ...

  7. 用js判断是否是微信浏览器

      //判断是否是微信浏览器的函数 function isWeiXin(){ //window.navigator.userAgent属性包含了浏览器类型.版本.操作系统类型.浏览器引擎类型等信息,这 ...

  8. js判断是否是微信浏览器以及重定向

    async created () {//这个是判断是否是微信浏览器, let ua = navigator.userAgent.toLowerCase() if (ua.match(/MicroMes ...

  9. js判断当前浏览类型

    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串var isOpera = userAgent.indexOf("Opera ...

随机推荐

  1. ML-线性回归

    记样本数目为$m$,样本点$i$用$(x^{(i)}, y^{(i)})$表示,其中 $x^{(i)}=\begin{pmatrix}x_1^{(i)}\\ x_2^{(i)}\\ ...\\x_n^ ...

  2. [DataBase] MongoDB (7) MongoDB 索引

    MongoDB 索引 1. 建立索引 唯一索引db.passport.ensureIndex( {"loginname": 1}, {"unique": tru ...

  3. windows10 下访问 virtualbox 虚拟机的linux15.10/16.04 系统 及 用 putty 访问虚拟机的配置

    参考: http://www.doc88.com/p-915707596190.html --- 安装samba http://my.oschina.net/u/2260265/blog/405598 ...

  4. asp.net type=file在上传图片到服务器

    前台 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> ...

  5. JAVA可阻塞队列-ArrayBlockingQueue子类BlockingQueue的应用,使用它来实现子线程打印10次,主线程打印100次,如此反复

    /** * 使用BlockingQueue实现主子线程互相打印 * @author duwenlei * */ public class BlockingQueueTest { public stat ...

  6. 类型转换bin()、chr()、ord() 、int()、float()、str()、repr()、bytes()、tuple(s )、 list(s )   、unichr(x ) 、 ord(x )  、 hex(x )  、          type()数据类型查询

    1.bin() 将整数x转换为二进制字符串,如果x不为Python中int类型,x必须包含方法__index__()并且返回值为integer: 参数x:整数或者包含__index__()方法切返回值 ...

  7. 基于Apache+php+mysql的许愿墙网站的搭建create database xyq; //创建xyq数据库

    1.准备CentOS7与CentOS5的基础配置 2.在两台虚拟机中配置yum. 3.在CentOS7中安装httpd与php与php-mysql PS:截图时已安装 CentOS7 关闭防火墙与se ...

  8. 简单利用Scanner对文件进行解析

    public class AvPrice{    static int count = 0;    static int sum = 0;    public static void main(Str ...

  9. 2.OC蓝牙功能

    一.  最早的蓝牙框架是GameKit,iOS7之前用的比较多,它有只能支持iOS设备间的传输,但是使用步骤简单,我们只需要搞清楚两个类就可以了. GKPeerPickerController:熟称浏 ...

  10. Cheatsheet: 2016 05.01 ~ 05.31

    Other Awesome Go - A curated list of awesome Go frameworks, libraries and software Visual Studio Cod ...