奇怪的IE漏洞 [英] weird IE bug

查看:48
本文介绍了奇怪的IE漏洞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IE中发现了一个明确的错误。如果您在Firefox中加载下面的页面

,则会出现您所期望的警报。如果你在IE6中使用它来运行它b $ b(使用sp2),警报就不会出现。评论出来的行

开始''div.class''使其有效。这是非常奇怪的,因为我可以看到
- 代码没有运行,而且它没有产生语法错误,

但它是'仍然阻止程序的其余部分运行。所有我可以猜到的是,javascript解析器已经在该行崩溃了

某些原因没有返回错误。使用setAttribute可以围绕

工作,但它仍然令人讨厌。


< html>

< head>< title>错误测试< / title>

< script type =" text / javascript">

function notCalled(){

var div = document.createElement(" div");

div.class =" tabContentPaneDiv" ;;

}


alert(" here");

< / script>

< / head>

< ; body>

< h1> IE错误测试< / h1>

< / body>

< / html>

解决方案


lo *** **@fastmail.fm 写道:

div.class =" tabContentPaneDiv" ;;




没有错误。要更改元素的类,正确的语法

是:


element.className =" classname";


将其更改为上述内容将导致您的警报显示。




web.dev写道:< blockquote class =post_quotes> lo*****@fastmail.fm 写道:

div.class =" tabContentPaneDiv";



没有错误。要更改元素的类,正确的语法是:

element.className =" classname" ;;

将其更改为上面将导致您的警告显示。




好​​的 - 我原来想要的是什么,但我还有错误的属性名称,但是仍有据我所知,这是一个错误。如果您更改上面的

行,那么函数显示为:


函数notCalled(){

var div = {class :0};

div.class =" tabContentPaneDiv" ;;

}


警报未显示。它在Firefox中。这不应该发生我想b / b
想想。


关键是函数永远不会被调用,所以唯一的时间是

javascript翻译应该在检查语法时查看它。

此时,解释器不应该为div

变量是dom节点还是打扰其他一些对象。但是即使它没有被调用,因此分配给属性名称''class'会导致

程序永远无法运行。




loft ... @ fastmail.fm写道:

web.dev写道:

lo*****@fastmail.fm 写道:

div.class =" ; tabContentPaneDiv";



没有错误。要更改元素的类,正确的语法是:

element.className =" classname" ;;

将其更改为上面将导致您的警告显示。



好的 - 我原来试图做的事情的属性名称错了,但就我所见,还有一个错误。如果您更改其上方的
行,则函数显示为:

函数notCalled(){
var div = {class:0};
div.class = tabContentPaneDiv;
}

警报没有显示出来。它在Firefox中。这不应该发生我想。

关键是函数永远不会调用,所以
javascript解释器应该只查看它的时候是检查语法。
此时,解释器不应该为div
变量是dom节点还是其他类型的对象而烦恼。但即使没有调用它,分配给属性名称''class'会导致
程序永远无法运行。




我刚刚发现''class''是javascript中的保留字,

可以解释这个,但如果是,则解释器应该给出语法

错误,而不仅仅是停止。这也无法解释为什么它在

firefox中运行正常。


I found what looks like a definite bug in IE. If you load the page
below in Firefox, the alert comes up as you would expect. If you run it
in IE6 (with sp2), the alert doesn''t come up. commenting out the line
that starts ''div.class'' makes it work. This is very weird, as far as I
can see - the code is not run, and it''s not generating a syntax error,
but it''s still preventing the rest of the program from running. All I
can guess is that the javascript parser has crashed on that line for
some reason without returning an error. It is possible to work round
this using setAttribute, but it''s annoying nonetheless.

<html>
<head><title>bug test</title>
<script type="text/javascript">
function notCalled() {
var div=document.createElement("div");
div.class="tabContentPaneDiv";
}

alert("here");
</script>
</head>
<body>
<h1>IE Bug Test</h1>
</body>
</html>

解决方案


lo*****@fastmail.fm wrote:

div.class="tabContentPaneDiv";



There is no bug. To alter a class for an element, the correct syntax
is:

element.className = "classname";

Changing it to the above will cause your alert to show up.



web.dev wrote:

lo*****@fastmail.fm wrote:

div.class="tabContentPaneDiv";



There is no bug. To alter a class for an element, the correct syntax
is:

element.className = "classname";

Changing it to the above will cause your alert to show up.



OK - I had the wrong attribute name for what I was originally trying to
do, but there is still a bug as far as I can see. If you change the
line above it so the function reads:

function notCalled() {
var div={class:0};
div.class="tabContentPaneDiv";
}

The alert doesn''t show up. It does in Firefox. This shouldn''t happen I
think.

The point is the function is never called, so the only time the
javascript interpreter should look at it is when checking for syntax.
At this point, the interpreter shouldn''t be bothered whether the div
variable is a dom node or some other kind of object. But even though
it''s not called, assigning to the property name ''class'' causes the
program never to be run.



loft...@fastmail.fm wrote:

web.dev wrote:

lo*****@fastmail.fm wrote:

div.class="tabContentPaneDiv";



There is no bug. To alter a class for an element, the correct syntax
is:

element.className = "classname";

Changing it to the above will cause your alert to show up.



OK - I had the wrong attribute name for what I was originally trying to
do, but there is still a bug as far as I can see. If you change the
line above it so the function reads:

function notCalled() {
var div={class:0};
div.class="tabContentPaneDiv";
}

The alert doesn''t show up. It does in Firefox. This shouldn''t happen I
think.

The point is the function is never called, so the only time the
javascript interpreter should look at it is when checking for syntax.
At this point, the interpreter shouldn''t be bothered whether the div
variable is a dom node or some other kind of object. But even though
it''s not called, assigning to the property name ''class'' causes the
program never to be run.



I just found out that ''class'' is a reserved word in javascript, which
may explain this, though if it is, the interpreter should give a syntax
error, not just stop. This also doesn''t explain why it runs OK in
firefox.


这篇关于奇怪的IE漏洞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆