`

if(!document.all) 的含义

阅读更多
一种一般用作识别IE浏览器的方法.


可以判断兼容性
IE下
if(document.all)
返回 true
firefox下
if(document.all)
返回 false

感谢 sohighthesky 分享的方法

sohighthesky 写道
识别ie我用
window.ActiveXObject
!+'\v1'
!-[1,]
现在更喜欢用短的了


引用

!!window.ActiveXObject&&!window.XMLHttpRequest


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″);
}
}
0
1
分享到:
评论
6 楼 sohighthesky 2010-02-23  
识别ie我用
window.ActiveXObject
!+'\v1'
!-[1,]
现在更喜欢用短的了
5 楼 wcily123 2010-02-23  
sohighthesky 写道
以前是为true的,之前9.64中


是很诡异,js各个浏览器实现的都不太一样。

呵呵 这种方法应该很少有人用,我在维护一个项目的时候,
看到这样写觉得和怪就上网查了一下 标记一下以后看到了不至于看不懂

sohighthesky 你平时是怎么识别浏览器类型的?
4 楼 sohighthesky 2010-02-23  
以前是为true的,之前9.64中
3 楼 sohighthesky 2010-02-23  
果真够诡异,
这个结果也能出来alert(document.all +"|"+(!document.all))
可以看出document.all在Opera也不会空,但是转换为bool时却为false真够奇怪的了
2 楼 wcily123 2010-02-23  

sohighthesky 写道
opera也返回true


我平时从来不用 opera 所以。。。
就这个问题我下载了一个最新的 opera (10.10) 测试了这个问题
我这里测试的结果 返回的是 false

<html>
<head>
    <script>
	if(document.all) {
		alert("ie");
	}else {
		alert("other");
	}
	</script>
</head>
<body></body>
</html>


测试结果,显示 other
1 楼 sohighthesky 2010-02-23  
opera也返回true

相关推荐

    JS的document.all函数使用示例

    document.all可以判断浏览器是否是IE if(document.all){ alert&#40;“is IE!”&#41;; } 三. 也可以通过给某个元素设置id属性(id=aaaa),然后用document.all.aaaa调用该元素 四. 案例: 代码1: 代码如下: &lt;input...

    JavaScript 数字时钟代码

    JavaScript 数字时钟代码 function Time(){ ...else if (document.all) position.innerHTML=myclock setTimeout("Time()",1000) } //--&gt; ;left:441px;top:190px; width: 128px; height: 30px"&gt; &lt;/span&gt;

    很酷的时钟 (跟随鼠标飘动的双层时钟!).

    ie=(document.all); Face=Face.split(' '); n=Face.length; a=size*10; ymouse=0; xmouse=0; scrll=0; props="&lt;font face="+font+" size="+size+" color="+fCol+"&gt;&lt;B&gt;"; props2=...

    JavaScript教程及实例讲解

    else if (document.all) position.innerHTML=myclock setTimeout("Time()",1000) } //--&gt; ;left:441px;top:190px; width: 128px; height: 30px"&gt; ②源程序讲解: function Time() 定义一个函数。 { if (!...

    让你的图片实现可以拖动的效果

    document.all) return if (event.srcElement.className=="drag"){ dragapproved=true z=event.srcElement temp1=z.style.pixelLeft temp2=z.style.pixelTop x=event.clientX y=event.clientY document.onmousemove=...

    document.all还是document.getElementsByName?

    代码如下:(wuhen注:document.all是ie特有的属性,不是万维网标准) 当页面上的控件同名且多个的时候,你首先做的是什么?判断长度?的确,从程序的严密角度出发,我们是需要判断长度,而且有长度和没长度是两种引用方法....

    再谈ie和firefox下的document.all属性

    – if(document.all) alert&#40;“this is a IE”&#41;; else alert&#40;“this is a Mozilla”&#41;; //–&gt; [removed] &lt;/body&gt; &lt;/html&gt; 在IE浏览器会输出 “this is a IE”; 而在firefox浏览器中会...

    实现星星跟随鼠标的特效

    if (document.all&&document.readyState=="complete"){ document.all.tooltip2.innerHTML='&lt;marquee style="border:1px solid black"&gt;'+text+'&lt;/marquee&gt;' document.all.tooltip2.style.pixelLeft=event.clientX+...

    document.all的一个比较完整的总结及案例

    代码如下: document.all可以判断浏览器是否是IE if(document.all){ alert&#40;“is IE!”&#41;; } 三. 也可以通过给某个元素设置id属性(id=aaaa),然后用document.all.aaaa调用该元素 四. 案例: 代码1: 代码如下:...

    javascript小技巧

    else if (document.all){ if (topmsg.style.visibility=="visible") topmsg.style.visibility="hidden" else topmsg.style.visibility="visible" setTimeout("display2()",Math.round(Math.random()*10000)+10000) }...

    javascript实现禁止右键和F12查看源代码

    if (document.all) { if (event.button==2||event.button==3) { alert&#40;“欢迎光临寒舍,有什么需要帮忙的话,请与站长联系!谢谢您的合作!!!”&#41;; oncontextmenu=’return false’; } } if (document....

    获取页面长宽和滚动条的位置

    } else if(document.body.scrollHeight &gt; document.body.offsetHeight) { // all but IE Mac scrW = document.body.scrollWidth; scrH = document.body.scrollHeight; } else if(document.body) { /...

    表单验证大全

    with(document.all){ if(input1.value!=input2.value) { alert&#40;"false"&#41; input1.value = ""; input2.value = ""; } else document.forms[0].submit(); } } [removed] 够了吧 :) 屏蔽右键 很酷 ...

    js 屏蔽鼠标右键脚本附破解方法

    /////////////////////////////////// function clickIE() {if (document.all) {(message);return false;}} function clickNS(e) {if (document.layers||(document.getElementById&&!document.all)) { if (e.which=...

    鼠标上滚动文字

    if (document.all) document.write(';width:250px;border:1px solid black;font-size:14px;background-color:white;visibility:hidden"&gt;'+scroller_msg+'&lt;/marquee&gt;') function followcursor(){ //move cursor ...

    JavaScript中也使用$美元符号来代替document.getElementById

    代码如下:function $(id){return document.getElementById(id); 上面的对于新版本的浏览器都是没有问题的,如果使用古老的浏览器,可以使用下面的函数 ... } else if (document.all && document.all(objectId)) { //

    跟随鼠标的萤火虫

    }}function hidetip2(){if (document.all)document.all.tooltip2.style.visibility=&quot;hidden&quot;else if (document.layers){clearInterval(currentscroll)document.tooltip2.visibility=&quot;hidden&quot;}}...

    asp.net菜单(很简单)

    dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, previousmenuitem:null, currentpageurl: window.location.href.replace("http://"+window.location.hostname, "")....

    JSCode all of Brower 全局屏蔽网页右键功能 具体实现

    [javascript] 代码如下:[removed] function clickIE4(){ if (event.button==2){ return false; } } function clickNS4(e){ if (document.layers||document....document.all){ if (e.which==2||e.which==3){

    比较简洁的JavaScript 实时显示时间的脚本 修正版

    document.all) return 由于IE与Netscape对JavaScript的解释不同,造成浏览的效果不同,所以要分别写代码。这句话判断一下用户所使用的浏览器,如果两者都不是,就返回。 var timer=new Date() 定义一个新的...

Global site tag (gtag.js) - Google Analytics