Bug Tracker

Opened 10 years ago

Closed 10 years ago

#14802 closed bug (fixed)

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

Description

http://www.quora.com/Why-does-jquery-trigger-window-onready

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();

}code

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 (3)

comment:1 Changed 10 years ago by dmethvin

Component: unfiledcore
Milestone: None1.11.1/2.1.1
Priority: undecidedhigh
Status: newopen

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

comment:2 Changed 10 years ago by dmethvin

Owner: set to dmethvin
Status: openassigned

comment:3 Changed 10 years ago by Dave Methvin

Resolution: fixed
Status: assignedclosed

Core: Do not run window.onready when ready

Fixes #14802

Changeset: 2df1aad6a1c9376c2a477eba26ee992113ed1c23

Note: See TracTickets for help on using tickets.