#4187 closed bug (invalid)
document.ready fires too early on safari
Reported by: | tipiirai | Owned by: | tipiirai |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | event | Version: | 1.2.6 |
Keywords: | document, ready | Cc: | |
Blocked by: | Blocking: |
Description
Safari fires $(document).ready() is fired too early when there are external stylesheets. When accessing CSS properties inside that event they are not properly set. You can see an example page here:
http://flowplayer.org/demos/test/jquery1.htm
In Firefox (for example) the css() method gives correct result (300px) but in Mac/Safari it gives the full length of the DIV - stylesheet property not yet applied.
$(window).load() fixes the situation and when styles are defined inline on the page and not in external stylesheet.
I have experienced this on 1.2.6 and 1.3.1 and on many different scenarios. I think this is quite serious because when components rely on initial CSS properties Safari won't work.
Change History (17)
comment:1 Changed 14 years ago by
comment:3 Changed 14 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
Correct, and this is documented:
http://docs.jquery.com/Events/ready#fn
Safari is picky about this.
comment:4 Changed 14 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Unfortunately this is not the case. I moved the stylesheet as the first element on the page. Even before the jquery script inclusion. When the stylesheet was small there seemed to be no problems. However when I made the stylesheet larger the page was behaving badly
http://flowplayer.org/demos/test/jquery1.htm
sometimes css() method gets it right and sometimes not.
comment:5 Changed 14 years ago by
Try <strong>reloading</strong> the page multiple times with safari.
comment:6 Changed 14 years ago by
Can you try it with a complete document? (doctype, head, body, etc.)
comment:7 Changed 14 years ago by
yes. test page is now a complete document. the bug is still there - maybe it doesn't come that often now perhaps one out of ten reloads gives a falsy result.
comment:9 Changed 14 years ago by
It has been there all the time. The same test page has been modified:
comment:10 Changed 14 years ago by
As frustrating as this issue is a simple workaround is to use a setTimeout with 1ms within document.ready. I think it mostly has to do with redraw issues in Safari.
comment:11 Changed 14 years ago by
This basically means that every time I want to use document.ready with external CSS I have to use this setTimeout trick to make pages work in a cross browser manner. I'm in a little doubt this even works on large CSS files - anyway this kind of tricks should be included in the jQuery and not for the responsibility for jQuery users.
I'd say this issue is still open.
comment:12 Changed 14 years ago by
Owner: | brandon deleted |
---|---|
Priority: | critical → major |
Status: | reopened → new |
Unfortunately the DOMContentLoaded method doesn't always guarantee that *external* css assets will be loaded. If your code depends on external css, then you should use load for now.
comment:13 follow-up: 14 Changed 14 years ago by
I can confirm this bug and tested some solutions here (http://www.rosamez.com/?p=200) - maybe I'm wrong, but Dean and John's one (http://dean.edwards.name/weblog/2006/06/again/) is okay, but instead of testing for loaded OR complete, only "complete" is good for us. I'm not sure if it is any better than onload (in terms of downloaded content), but hope it helps. Thanks.
comment:14 Changed 14 years ago by
Sorry for the above comment, oncomplete is pretty much body onload, now I know ;) + on a webserver it doesn't happen very often (assuming I move all css *before* jQuery), on localhost, where everything is much faster it does happen sometimes (1-2 out of 10), but I can live with a small timeout I guess.
comment:45 Changed 12 years ago by
Owner: | set to tipiirai |
---|---|
Status: | new → pending |
The test case is no longer valid. Please provide a valid test case. If this issue no longer exists, please ignore this message, and the bug will be closed automatically.
comment:46 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | pending → closed |
Automatically closed due to 14 days of inactivity.
I raported about this 6 months ago for the first time on this ticket:
http://dev.jquery.com/ticket/3312#comment:5
at that time I didn't know the specific problem and the ticket was not accurate. now I have a demo page that clarly shows what's all about.
Anyway: Thank you for developing jQuery - it has changed my world.