Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / August 2007



Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fan - 30 Aug 2007 15:20 GMT
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?
David Golightly - 30 Aug 2007 17:54 GMT
> test page:
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://www.w3.org/TR/html4/strict.dtd">
[quoted text clipped - 16 lines]
> --></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
David Golightly - 30 Aug 2007 18:01 GMT
> > test page:
> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://www.w3.org/TR/html4/strict.dtd">
[quoted text clipped - 29 lines]
>
> -David

not "non-transitive", "asymmetric".  Apologies.
Stevo - 30 Aug 2007 18:02 GMT
> IE6 & IE7 seems to have a non-transitive comparison operator.

?
Evertjan. - 30 Aug 2007 18:57 GMT
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
[quoted text clipped - 6 lines]
>
> 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>

Signature

Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

David Golightly - 30 Aug 2007 19:13 GMT
On Aug 30, 10:57 am, "Evertjan." <exjxw.hannivo...@interxnl.net>
wrote:
> David Golightly wrote on 30 aug 2007 in comp.lang.javascript:
>
[quoted text clipped - 29 lines]
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

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

-David
Randy Webb - 30 Aug 2007 20:26 GMT
David Golightly said the following on 8/30/2007 2:13 PM:

<snip>

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

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.

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

Signature

Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

dhtmlkitchen@gmail.com - 31 Aug 2007 05:20 GMT
> David Golightly said the following on 8/30/2007 2:13 PM:
>
[quoted text clipped - 7 lines]
> 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
> --
> Randy
> Chance Favors The Prepared Mind
> comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
> Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
Thomas 'PointedEars' Lahn - 31 Aug 2007 00:53 GMT
> test page:
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//ZH-CN" "http://
[quoted text clipped - 17 lines]
> --></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
Signature

var bugRiddenCrashPronePieceOfJunk = (
   navigator.userAgent.indexOf('MSIE 5') != -1
   && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.