Bug Tracker

Opened 10 years ago

Closed 9 years ago

Last modified 8 years ago

#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)

chrome.rar (92.3 KB) - added by Artem 10 years ago.
main_before.html - use original jQuery, main_before.html - use corrected jQuery

Download all attachments as: .zip

Change History (4)

Changed 10 years ago by Artem

Attachment: chrome.rar added

main_before.html - use original jQuery, main_before.html - use corrected jQuery

comment:1 Changed 9 years ago by jessicah

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 9 years ago by Rick Waldron

Owner: set to Artem
Priority: undecided
Status: newpending

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 9 years ago by trac-o-bot

Status: pendingclosed

Automatically closed due to 14 days of inactivity.

Note: See TracTickets for help on using tickets.