简体   繁体   中英

IE9 javascript undefined errors

I tried fixing my application to work on IE9 browser (with IE9 standards mode).

However I am getting some undefined javascript errors..

I have the following piece of code in a js file.

1.

if(escape(String.fromCharCode(111)).toLowerCase() != "abc")

{

    //code

}

I get error 'escape' is undefined.

2. In some js files, I get errors "Array is undefined" for such piece of code

//1
function abc(){

this.abc = new Array();

}


//2

var cde = new Array
(

  "aaa","bb","cc",

  "dd","eee","ff",  

);

However these errors do not occur for IE8 standards mode and other modes.

Please let me know why these errors are coming and how to fix such errors.

While Ryan's answer fixes the issue, the problem here is the trailing comma;

"dd","eee","ff",

Your abc function turns itself into an array object; this is window . Maybe the context of this has changed or was misunderstood somewhere, and the code is inadvertently redefining window or its properties. That could explain why globals like Array and escape are undefined. (Not sure why it would only affect IE9 standards mode, though.)

Instead of using new Array(...), can you simply say...

this.abc = [];

and...

var cde = ['aaa','bb','cc','dd','eee','ff'];

...?

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