Bug Tracker

Ticket #14802 (closed bug: fixed)

Opened 22 months ago

Last modified 21 months ago

User defined onready function on the window is triggered when jQuery is present on the page

Reported by: harshabn808@… Owned by: dmethvin
Priority: high Milestone: 1.11.1/2.1.1
Component: core Version: 1.11.0-rc1
Keywords: Cc:
Blocking: Blocked by:



If I define: function onready(){ console.log("logged"); } in the global scope, nothing happens.

But if I include jquery, this function will be called.

This is what is happening -

[code]if ( document.addEventListener
event.type === "load" document.readyState === "complete" ) {

detach(); jQuery.ready();


This snippet of code is called when document's content is loaded (DOMContentLoaded or onreadystatechange). "jQuery.ready()" when called, is triggering a ready event on the document (this is to handle $(document).ready). But jQuery goes further ahead, bubbles up the event to window and checks for the presence of any events of the same type are present on the ancestors. In this case, you do have defined a onready function on the window. So, it calls the function. This is totally wrong and shouldn't happen.

Change History

comment:1 Changed 22 months ago by dmethvin

  • Priority changed from undecided to high
  • Status changed from new to open
  • Component changed from unfiled to core
  • Milestone changed from None to 1.11.1/2.1.1

Agreed, we can just do a .triggerHandler() instead, which won't bubble and won't fire any associated method.

comment:2 Changed 21 months ago by dmethvin

  • Owner set to dmethvin
  • Status changed from open to assigned

comment:3 Changed 21 months ago by Dave Methvin

  • Status changed from assigned to closed
  • Resolution set to fixed

Core: Do not run window.onready when ready

Fixes #14802

Changeset: 2df1aad6a1c9376c2a477eba26ee992113ed1c23

Note: See TracTickets for help on using tickets.