Opened 9 years ago
Closed 9 years ago
#14802 closed bug (fixed)
User defined onready function on the window is triggered when jQuery is present on the page
Reported by: | 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 -
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 9 years ago by
Component: | unfiled → core |
---|---|
Milestone: | None → 1.11.1/2.1.1 |
Priority: | undecided → high |
Status: | new → open |
comment:2 Changed 9 years ago by
Owner: | set to dmethvin |
---|---|
Status: | open → assigned |
comment:3 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Core: Do not run window.onready when ready
Fixes #14802
Changeset: 2df1aad6a1c9376c2a477eba26ee992113ed1c23
Agreed, we can just do a
.triggerHandler()
instead, which won't bubble and won't fire any associated method.