Skip to main content

Bug Tracker

Side navigation

#6588 closed bug ()

Opened May 20, 2010 06:50AM UTC

Closed November 11, 2010 11:09PM UTC

Last modified March 13, 2012 07:59PM UTC

$(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 May 20, 2010 06:53AM UTC.

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

Change History (3)

Changed July 01, 2010 04:01AM UTC by jessicah comment:1

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.

Changed October 25, 2010 07:58PM UTC by rwaldron comment:2

owner: → 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?

Changed November 11, 2010 11:09PM UTC by trac-o-bot comment:3

status: pendingclosed

Automatically closed due to 14 days of inactivity.