#4406 closed bug (duplicate)
jQuery doesn't wait for page to load.
Reported by: | Phil | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | support | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
On pages that take a while to load (few seconds) jQuery trys to access document.body before it has fully loaded.
This causes no jQuery scripts to be executed on the page.
I am getting this error repeatedly on certain pages of my website.
The piece of code causing the issue is:
Figure out if the W3C box model works as expected document.body must exist before we can do this jQuery(function(){
var div = document.createElement("div"); div.style.width = div.style.paddingLeft = "1px";
document.body.appendChild( div ); jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2; document.body.removeChild( div ).style.display = 'none';
});
Despite the fact the comment correctly points out that document.body must exist there is no check done to ensure it does exist, hence causing a script error.
Change History (7)
comment:1 Changed 15 years ago by
comment:2 Changed 15 years ago by
need: | Review → Test Case |
---|
Please create a simplified test case that shows where this is failing for you.
comment:3 Changed 15 years ago by
Priority: | blocker → major |
---|
comment:4 Changed 15 years ago by
I have modded the jquery source on my website but I can revert it back to the original 1.3.2 file and give you the link?
If I repeatedly press f5 on the home page with 1.3.2 I get repeated errors in the FF console.
comment:5 Changed 14 years ago by
I'm getting the same error. I just wanted to point out that i'm using IE and it's quite random. I'm getting the impression there are some delays declaring document.body.
comment:7 Changed 14 years ago by
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I've played around with this a bit and have come to the conclusion that it may be an issue with Firefox itself.
Firefox should send the ready event when the HTML is loaded but not nescessarily all the images, the remaining image on one page of my site is a background illustration of around 250kb which takes a couple of seconds to load, however if I modify the jQuery code with the following:
Which should work in theory as at this point the HTML should all be loaded I still get the error.
Change this to an onload as follows:
The error is gone, the jQuery effects and plugins also seam to function normally with this modification.
I'm sure this isn't an ideal solution but rather than sift through 4,000 lines of unfamiliar code looking for a better alternative it seams to be an adequate work around for now.