Skip to content Skip to sidebar Skip to footer

Window Object Acting Strange In Chrome And Ie

Consider the following sample HTML:
And the following script var about = (function ($, window, document) { 'us

Solution 1:

The WebKit browsers seem to ape the old IE behavior of treating element "id" values as properties of the window object.

I dislike the behavior, personally.

Solution 2:

Chrome will take any ID in the HTML and turn it into a global variable. You can overwrite the assignment, but I assume you're checking for existence and not overwriting perhaps?

http://jsfiddle.net/robert/Hnw7y/

Solution 3:

One way to differentiate between the HTMLElement and the function would be to check the object's type:

if (typeofwindow.about === 'function') {
    // the 'about' function has been defined
}

Solution 4:

Unfortunately the only way you can do this is the following:

functionglobal(name) { returneval(name); }

if( global("about") )
   ...

Try this: http://jsfiddle.net/PMqPv/1/

Post a Comment for "Window Object Acting Strange In Chrome And Ie"