Bart
Bart

Reputation: 10015

jQuery $(document).ready() failing in IE6 but only after clearing Temporary Internet Files

I'm experiencing problems with $(document).ready not getting executed in IE6, but only after clearing the Temporary Internet Files (so in fact the very first time this page is loaded). On refreshing the page or on later page loads, everything works fine.

This is the current setup:

<script language="javascript">

try{

$("#CR").remove();

} catch(ex){ }

$(document).ready(function() { alert(typeof $); // check if method is getting executed RendererPageIsLoading(); // loads data in comboboxes and hides divs });

</script> </body>

I'm using the latest version of jQuery (1.4.2). Edit: jquery is getting loaded in the head section of the current page:

<script language="javascript" type="text/javascript" src="https://fulldomain/js/jquery.js"></script>

Following topic didn't bring any solutions: jQuery $(document).ready() failing in IE6

Upvotes: 0

Views: 867

Answers (2)

Fenton
Fenton

Reputation: 250802

If you are adding a script immediately before the "/body" tag, you don't need to use:

$(document).ready(...);

As the document IS ready (bar from "/body" and "/html").

It is really useful if you have an external JavaScript file that may be loaded faster than the page - in which case it delays the execution until the DOM is ready (or in some browsers the DOM and HTTP requests... which is more like window.onload, which waits for all the images, for example).

Upvotes: 0

Bart
Bart

Reputation: 10015

Someone suggested (he did remove his answer later on) that attaching a method to the window.onload did detach the method defined in the $(document).ready() event. However since the error only happened the first time the page was loaded, in my opinion this had to be a cache problem.

After further investigation we found out that IE6 was having problems with a transparent png that didn't get loaded correctly. Therefor the browser is waiting for the image to load and IE6 waits on images before it triggers the DOM ready event.

Conclusion: also check for transparent png images if having problems with IE6.

Upvotes: 3

Related Questions