View Full Version : IE issue with javascript code

06-18-2009, 09:42 AM
Hello Everyone,
I have an issue with IE (6, 7 and 8). I have a js file, which is importing another js file, in which is defined a variable and is being accessed in the former mentioned js file. In IE, the IE developer toolbar shows that the call to the variable is happening only after the js file is being imported. But rendering wise that is not happening and IE is throwing a script error saying the variable is not defined.
In Firefox, this works fine with absolutely no issues or script errors (which is confirmed using firebug).
Is this a known issue with IE or is it something else?
Please help me out people.

Philip M
06-18-2009, 12:04 PM
This may be the old IE bug where a short delay of say 50ms is required before the variable is accessed.

var tim = setTimeout("getTheValue()",50);
var val;

function getTheValue() {
val = whatever;

06-18-2009, 01:23 PM
Thanks a lot for your time.
I tried out what you have suggested. It still is giving the same undefined error. Is there any chance that IE is unable to locate the file in the mentioned path? AFAIK, that should not happen either.
Please do let me know.

Philip M
06-18-2009, 01:34 PM
As you have not posted any code it is not easy to identify your problem.

Please post your relevant (stripped down) code. Then we can try to work out what is wrong.

06-18-2009, 01:42 PM
Here you go,

var += "<script type=\"text/javascript\" src=\"/objects/javascript/smileys.js\">";
var += "</script>";
var += "<script type=\"text/javascript\">";
var += "var1.containers = ['smileywide'];";
var += "obj.var1.init (var1);";
var += "</script>";

IE throws 2 script errors, "var1 is undefined" and "obj is undefined", simultaneously.

06-19-2009, 02:04 PM
Got it. Thanks to Philip for giving me a something to start with. Yes, IE has a stupid lag due to which i could not use any of the js components, soon after it was imported. Hence i imported it at the load of the page and now it is fine.
Thanks a lot!