Ticket #3312 (closed bug: duplicate)
dimension methods not working on document.ready on safari
| Reported by: | tipiirai | Owned by: | brandon |
|---|---|---|---|
| Priority: | major | Milestone: | 1.3 |
| Component: | event | Version: | 1.2.6 |
| Keywords: | Cc: | tipiirai, flesler | |
| Blocking: | Blocked by: |
Description
I tried with element.outerWidth() and it always returns the full window width when on document.ready. However after one millisecond after loading the width is correct.
Attachments
Change History
comment:1 Changed 5 years ago by flesler
- Cc tipiirai, flesler added
- need changed from Review to Test Case
comment:2 Changed 5 years ago by anderhagen
I discovered the same behaviour, and did some testing. When I defined the styles in the head of the HTML-doc (instead of linking to a CSS-file) it worked fine... It seams that the document.ready event maybe doesn't wait for external CSS files to load before firing (In Safari at least)...? The CSS file just contained 10 lines of code, and I run it on a local server, so response/download times shouldn't be an issue.
Safari 3.1.2, Win XP
Changed 5 years ago by andrewharrison
-
attachment
safari-test.zip
added
test case for safari document ready issue
comment:3 Changed 5 years ago by andrewharris
I concur with the previous message. This is quite tricky to replicate. When I run a test from the file system, it works ok. When I run it from a server running on localhost, it fails. When the css is included it works ok, when the css file is referenced, it fails. I've attached a simple test case which includes a separate css file, and commented out inline css. It also has a timeout() commented out on the function that invokes the dimensions. On my local machine, 10 ms works, but less doesn't.
the more complicated real problem I'm having returns variations of results, not just the window dimensions, i.e. some of the values (padding, border, margin etc) are correct and some are not.
If memory serves me, the callbacks from WebKit are a little unreliable.:-(
I'm running Safari 3.1.2 on Mac OS X 5.5 (Leopard). Hope this helps.
comment:4 Changed 5 years ago by flesler
- need changed from Test Case to Patch
- Owner set to brandon
- Component changed from core to dimensions
comment:6 Changed 4 years ago by tipiirai
Now I got a more clear description of the bug and a demo page.
The problem is that in Safari $(document).ready() is fired too early. There is no way to access CSS properties when using external stylesheets. Here is a demo
http://flowplayer.org/demos/test/jquery1.htm
in Firefox (for example) css() method gives correct result (300px) but not in Mac/Safari.
I have experienced this on 1.2.6 too and on many different scenarios. I think this is quite serious because when components rely on initial CSS properties Safari won't work. $(window).load() fixes the situation.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Your details are not quite enough to be able to handle this. Could you provide a test case ? a minimalistic html file with the requires html and js to reproduce the problem. Thanks.