(window == any_element) always return true in IE6?

F

Fan

test page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://
www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title></title>
</head>
<body>
<input type=button id=a onclick=checkme() value=clickme>
</body>
</html>
<script type="text/javascript"><!--
function checkme() {
var a = document.getElementById("a");
alert("window==a? "+(window==a)); //true
alert("a==window? "+(a==window)); //false
}
--></script>
is it a bug of IE?
 
D

David Golightly

test page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title></title>
</head>
<body>
<input type=button id=a onclick=checkme() value=clickme>
</body>
</html>
<script type="text/javascript"><!--
function checkme() {
var a = document.getElementById("a");
alert("window==a? "+(window==a)); //true
alert("a==window? "+(a==window)); //false
}
--></script>
is it a bug of IE?

Disregarding for a minute the script tag you have outside your HTML
tag (invalid!), this does indeed seem to be true: JScript in IE6 & IE7
seems to have a non-transitive comparison operator. You can try it by
navigating to http://www.google.com on IE and copy/pasting the
following into your address bar:

javascript:var g=document.getElementById('lgpd');alert((window==g)+','+
(g==window));

Now *THAT* is some serious junk code.

-David
 
D

David Golightly

Disregarding for a minute the script tag you have outside your HTML
tag (invalid!), this does indeed seem to be true: JScript in IE6 & IE7
seems to have a non-transitive comparison operator. You can try it by
navigating tohttp://www.google.comon IE and copy/pasting the
following into your address bar:

javascript:var g=document.getElementById('lgpd');alert((window==g)+','+
(g==window));

Now *THAT* is some serious junk code.

-David

not "non-transitive", "asymmetric". Apologies.
 
E

Evertjan.

David Golightly wrote on 30 aug 2007 in comp.lang.javascript:
Disregarding for a minute the script tag you have outside your HTML
tag (invalid!), this does indeed seem to be true: JScript in IE6 & IE7
seems to have a non-transitive comparison operator. You can try it by
navigating to http://www.google.com on IE and copy/pasting the
following into your address bar:

javascript:var g=document.getElementById('lgpd');alert((window==g)+','+
(g==window));

Now *THAT* is some serious junk code.

Let's keep it simple and compare:

<body>
<script type='text/javascript'>
var g=document.body;
alert((window == g)+','+(g == window));
</script>

and:

<body>
<script type='text/javascript'>
var g=document.body;
alert((window === g)+','+(g === window));
</script>
 
D

David Golightly

David Golightly wrote on 30 aug 2007 in comp.lang.javascript:




Let's keep it simple and compare:

<body>
<script type='text/javascript'>
var g=document.body;
alert((window == g)+','+(g == window));
</script>

and:

<body>
<script type='text/javascript'>
var g=document.body;
alert((window === g)+','+(g === window));
</script>

Whichever way you slice it, same result. How 'bout that: IE's
equality operator is apparently broken.

-David
 
T

Thomas 'PointedEars' Lahn

Fan said:
test page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://
www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title></title>
</head>
<body>
<input type=button id=a onclick=checkme() value=clickme>
</body>
</html>
<script type="text/javascript"><!--
function checkme() {
var a = document.getElementById("a");
alert("window==a? "+(window==a)); //true
alert("a==window? "+(a==window)); //false
}
--></script>
is it a bug of IE?

Your code is completely invalid: http://validator.w3.org/

But know this: `window' is a reference to a host object. With host objects,
all bets are off per the ECMAScript language specification. And MS JScript
is an ECMAScript implementation.


PointedEars
 
D

dhtmlkitchen

David Golightly said the following on 8/30/2007 2:13 PM:



It isn't IE's equality operator, it is IE's resolution of the window
object. If it were the equality operator then the the alerts would be
the same for window==g and g==window and they aren't. That alone says it
isn't the operator but something else.

More on IE and window.event, see Dean's comment on window being not
equal to window.

http://www.davidflanagan.com/blog/2007_03.html

Interesting post on attachEvent's event argument.
http://www.davidflanagan.com/blog/2006_10.html#000114

Why anybody would need to compare a variable to window eludes me though.

IF you have a popup or iframe.

var win = iframe.contentWindow;

window is weird in IE.

Garrett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top