Bug Tracker

Modify

Ticket #6588 (closed bug)

Opened 3 years ago

Last modified 14 months ago

$(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:
Blocking: Blocked by:

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

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

Change History

Changed 3 years ago by Artem

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

comment:1 Changed 3 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 3 years ago by rwaldron

  • Owner set to Artem
  • Priority set to undecided
  • Status changed from new to 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 3 years ago by trac-o-bot

  • Status changed from pending to closed

Automatically closed due to 14 days of inactivity.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.