1) in the browser, window.load and body.load are the same event and the body.load replaces the window load event. as there can only be one event handler, when you use jquery, it replaces the event handler with its own, and delegates the original events.
in jquery events are fired in the order they are defined. move the script block to after body, and you will change the order.
2) there is no document onload event.
3) the real javascript code is in jquery. its pretty complex, becuase $.ready wants to attach to dom.ready, but IE browsers are poor at firing dom ready. it also wants to use addListener, but its not supported in all browsers. if the browser fails to fire
dom.ready before window.load, then window load event will be used instead.
to understand the jquery event model, just read the source, it pretty straight forward.
window.load and body.load are the same event and the body.load replaces the window load event. as there can only be one event handler,
But "Windows All Complete" is still happening. So it won't replace window.load event. How can u explain that?
bruce (sqlwork.com)
2) there is no document onload event.
Why? Isn't this: $(document).load(function(){ alert("DOM All Completes");});
bruce (sqlwork.com)
3) the real javascript code is in jquery. its pretty complex, becuase $.ready wants to attach to dom.ready, but IE browsers are poor at firing dom ready. it also wants to use addListener, but its not supported in all browsers. if the browser fails to fire dom.ready
before window.load, then window load event will be used instead.
How can I understand what DOM is? Can u give me a living sample to explain that?
when jquery attaches its event handler it checks for existsing events, and adds them to the callback collection. also if the browsers supports it, jquery uses addEventListener, rather than window.load = function() {....}.
in the above code, only one alert will appear, the last one defined. jquery supports mutilple load event handlers, either via callback or addeventlistener.
2) $(document).load(function(){ alert("DOM
All Completes");});
will not fire because there is no document load event. the only dom element that reliably fires a load event is window. <img> has some issues with different browses but is mostly reliable.
2) $(document).load(function () { alert("DOM
All Completes"); });
will not fire because there is no document load event. the only dom element that reliably fires a load event is window. <img> has some issues with different browses but is mostly reliable.
No document load event?!
Isn't $(document).load to attach load event to document?
There is no $(document).load(handler) define in jQuery API. you can check it at
http://api.jquery.com/load-event/ . the load event raise when the page is fully loaded, including all frames, objects and images. it can attach to window object not document.
best regards,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
ToughMan
Participant
1490 Points
635 Posts
Why document.load isn't raised?
Jan 21, 2013 07:25 AM|LINK
Here's my codes of a pure HTML page:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="Scripts/jquery-1.8.3.js"></script> <script> $(function () { alert("DOM Completes"); }); $(window).ready(function () { alert("Window Completes"); }); $(window).load(function () { alert("Window All Completes"); }); $(document).load(function () { alert("DOM All Completes"); }); </script> </head> <body onload="alert('Body all completes!');"> <form id="form1" runat="server"> <div> </div> </form> </body> </html>Plz notice my bold statements. Now my questions are:
1) Why "Body all complete" is later than "window completes" and "window all completes"?
2) Why "DOM All Completes" never pops up?
3) What's the REAL javascript codes of my given above three jQuery's codes?
bruce (sqlwo...
All-Star
36836 Points
5443 Posts
Re: Why document.load isn't raised?
Jan 21, 2013 04:40 PM|LINK
1) in the browser, window.load and body.load are the same event and the body.load replaces the window load event. as there can only be one event handler, when you use jquery, it replaces the event handler with its own, and delegates the original events. in jquery events are fired in the order they are defined. move the script block to after body, and you will change the order.
2) there is no document onload event.
3) the real javascript code is in jquery. its pretty complex, becuase $.ready wants to attach to dom.ready, but IE browsers are poor at firing dom ready. it also wants to use addListener, but its not supported in all browsers. if the browser fails to fire dom.ready before window.load, then window load event will be used instead.
to understand the jquery event model, just read the source, it pretty straight forward.
ToughMan
Participant
1490 Points
635 Posts
Re: Why document.load isn't raised?
Jan 22, 2013 04:43 AM|LINK
So first many many thanks!
But——
But "Windows All Complete" is still happening. So it won't replace window.load event. How can u explain that?
Why? Isn't this: $(document).load(function () { alert("DOM All Completes"); });
How can I understand what DOM is? Can u give me a living sample to explain that?
bruce (sqlwo...
All-Star
36836 Points
5443 Posts
Re: Why document.load isn't raised?
Jan 22, 2013 03:23 PM|LINK
when jquery attaches its event handler it checks for existsing events, and adds them to the callback collection. also if the browsers supports it, jquery uses addEventListener, rather than window.load = function() {....}.
ToughMan
Participant
1490 Points
635 Posts
Re: Why document.load isn't raised?
Jan 23, 2013 02:25 AM|LINK
I still cannot understand:
But "Windows All Complete" is still happening. So it won't replace window.load event. How can u explain that?
Why? Isn't this: $(document).load(function () { alert("DOM All Completes"); }); raised?????
bruce (sqlwo...
All-Star
36836 Points
5443 Posts
Re: Why document.load isn't raised?
Jan 23, 2013 03:10 AM|LINK
1) you are confusing brower event setup and jquery. try:
<html> <body onload="alert('body.onload')"> </body> <script> window.onload=function(){alert('window.onload')}; </script> </html>and
<html> <script> window.onload=function(){alert('window.onload')}; </script> <body onload="alert('body.onload')"> </body> </html>in the above code, only one alert will appear, the last one defined. jquery supports mutilple load event handlers, either via callback or addeventlistener.
2) $(document).load(function () { alert("DOM All Completes"); });
will not fire because there is no document load event. the only dom element that reliably fires a load event is window. <img> has some issues with different browses but is mostly reliable.
ToughMan
Participant
1490 Points
635 Posts
Re: Why document.load isn't raised?
Jan 23, 2013 08:58 AM|LINK
No document load event?!
Isn't $(document).load to attach load event to document?
Sorry I'm really puzzling.
bruce (sqlwo...
All-Star
36836 Points
5443 Posts
Re: Why document.load isn't raised?
Jan 23, 2013 03:10 PM|LINK
yes, but as the browser will not fire a document load event, you need to write code to do it yourself.
$(document).trigger('load');
call this when you want the load event to fire.
ToughMan
Participant
1490 Points
635 Posts
Re: Why document.load isn't raised?
Jan 24, 2013 04:58 AM|LINK
Why should I use this?
But why “$(document).load(......)” isn't useful???
Yanping Wang...
Star
14871 Points
1529 Posts
Microsoft
Re: Why document.load isn't raised?
Jan 24, 2013 06:57 AM|LINK
Hi ToughMan,
There is no $(document).load(handler) define in jQuery API. you can check it at http://api.jquery.com/load-event/ . the load event raise when the page is fully loaded, including all frames, objects and images. it can attach to window object not document.
best regards,
Feedback to us
Develop and promote your apps in Windows Store