简体   繁体   中英

Undefined is not defined in IE7

I am using a JavaScript library (History.js) where the code is wrapped around this anonymous function:

 (function(window,undefined){
     //...
 })(window);

It works well in all browsers until I switch to IE7 compatibility mode. I drilled down to this "undefined" variable which is causing a script not being functional. In other words, IE7 seems to stop the script when it sees this undefined keyword.

I understand that this variable is used to create an undefined object but since it is really not defined anywhere, IE7 and possibly earlier do not work.

What's the workaround? has anybody come across the same issue?

The explanation and fix for this is here:

https://github.com/browserstate/history.js/issues/157

You just need to include json2.js before your code ( https://github.com/douglascrockford/JSON-js )

the snippet above does not actually execute the function. is this a copy/paste error? or is this your exact code? if so, try this:

(function(window, undefined) {
    //...
})(this);

note the final parentheses and the this object being passed (which maps back to the local var window inside the function.

hope that helps! cheers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM