Side navigation
#14802 closed bug (fixed)
Opened February 15, 2014 03:41PM UTC
Closed March 05, 2014 02:50AM UTC
User defined onready function on the window is triggered when jQuery is present on the page
Reported by: | harshabn808@yahoo.co.in | 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.
Agreed, we can just do a
.triggerHandler()
instead, which won't bubble and won't fire any associated method.