#6588 closed bug
$(document).ready() error in Google Chrome
Reported by: | Artem | Owned by: | Artem |
---|---|---|---|
Priority: | undecided | Milestone: | 1.4.2 |
Component: | event | Version: | 1.4.2 |
Keywords: | Google Chrome, DOMContentLoaded | Cc: | |
Blocked by: | Blocking: |
Description
Recently I detected one error in Google Chrome. If I use $(document).ready(), this browser detect dimensions of the elements incorrectly.
It is because, Google Chrome incorrectly supported event: «DOMContentLoaded».
In first rar-file is error example.
First alert, which we can see, it’s result of: $(document).ready(function() {
browser.Alert();
}) Second alert it’s result of: <body onload="browser.Alert()">
In first case in Google Chrome we have $("div.top").height()=0
Because I suggest rewrite something in bindReady in jquery.js.
Before:
if ( document.addEventListener ) {
Use the handy event callback document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
A fallback to window.onload, that will always work window.addEventListener( "load", jQuery.ready, false );
}
After:
if ( document.addEventListener ) {
if (navigator.userAgent.toLowerCase().indexOf('chrome')) {
window.addEventListener( "load", jQuery.ready, false );
} else {
Use the handy event callback document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
A fallback to window.onload, that will always work window.addEventListener( "load", jQuery.ready, false );
}
}
This exaple is in second rar-file.
Attachments (1)
Change History (4)
Changed 13 years ago by
Attachment: | chrome.rar added |
---|
comment:1 Changed 13 years ago by
Also having this issue in Chrome 5.x. Ended up just using window.onload and dropping $(document).ready(..) to resolve the issue. $("#someImage").width() always returned 0.
comment:2 Changed 12 years ago by
Owner: | set to Artem |
---|---|
Priority: | → undecided |
Status: | new → pending |
With regard to image loading and testing their widths: DOMContentLoaded will always fire before the width of all images is known as it is triggered when the DOM tree is parsed, much before all resources are loaded.
Regarding the original ticket description, I am not able to reproduce the described issue when using Chrome 7 - can you verify this issue still exists?
comment:3 Changed 12 years ago by
Status: | pending → closed |
---|
Automatically closed due to 14 days of inactivity.
main_before.html - use original jQuery, main_before.html - use corrected jQuery