(including images) before all DOM structures in the webpage can be executed after being drawn. The content associated with DOM elements is not loaded.You cannot write multipleThe following code cannot be correctly executed:Window. onload = function (){Alert ("text1 ");};Window. onload = function (){Alert ("text2 ");};
javaScript:
The Code is as follows:
Copy code
Window. onload = function (){// Write code}
Assume that the webpage has two functions, and the JavaScript code is as follows:
The Code is as follows:
Copy code
Function one (){Alert ("one ");}Function two (){Alert ("two ");}
After the webpage is loaded, us
.
$ (Document ). the ready () method can be used multiple times to register different event handlers, while the window. onload can only store reference to one function at a time. Multiple binding functions only overwrite the previous functions.First, let's take a look at the results of the window. onload method registering twice on a page:
Function one (){
Alert
: //code
3: }
Assume that the webpage has two functions, and the JavaScript code is as follows:
1: function one() {
2: alert("one");
3: }
4: function two() {
5: alert("two");
6: }
After the webpage is loaded, use Javascript code to call one function and two function respectively:
1: window.onload = one;
2: window.onload = two;
However, after runni
IE support the onload incident of IFrame, but is invisible, need to register through attachevent.The second method is more perfect than the first method (using ReadyStateChange judgment) because there are some potential problems with the ReadyStateChange event relative to the Load event.
The feeling here is not completely accurate, beginning to cause me a lot of trouble. See its code to understand, the real meaning of IE in the creation of a new IFRA
in this Article do this, but different browsers have different processing methods. Try the following code:The execution result is that when the parent page is loaded, the above IFRAME onload function will be activated in IE/Opera/safari, and Firefox will not respond to the second function. This is mainly because they have different processing methods in preventing recursion.For # hashonly and? The browser will interpret a URL such as search as the pa
these events is to do nothing before t where otherwise stated.6.1.6.4 Events and
WindowObject
When an event is dispatched at a DOM node inDocumentIn a browsing context, if the event is notloadEvent, the user agent must also dispatch the event toWindow, As follows:
In section 6.1.6.2, the window, document, and body objects are described in detail for their support for each event. Because they are too long, they will not be pasted out.
Ps: This article is purely a personal study. If there are
Http://forums.asp.net/983001/ShowPost.aspx
Want to add an onload JavaScript based on a condition from server-side code
I want to test for a condition in page_load event for a
(document.all) {Window.attachevent (' onload ', func1);Window.attachevent (' onload ', FUNC2);} else {Window.addeventlistener (' Load ', func1, false);Window.addeventlistener (' Load ', FUNC2, false);}
Is there any other way besides the above method?
Usage is as follows:
The code is as follows
Copy Code
function func () {alert
The OnLoad event, as the name implies, is for the JS program to execute after the Web page is loaded successfully. It is necessary for JS to be placed in the head.How to bind the Web page onload, there are three main ways:Window.onload=function () {//code to execute}Window.addeventlistener (' Load ', function name, false)Add Property DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.
executing the specified function after the DOM model of the page is loaded. $ (Document) is often used ). ready () to replace window. onload is because it is executed after the DOM model is loaded, while window. onload is executed only after the DOM element is fully loaded.B. About document. onload and window. onload:There is no essential difference between docu
The manipulation of elements and the binding of events need to wait for a suitable time to see the following example:DOCTYPE HTML>MetaCharSet= "Utf-8">HTML>Head> title>1-1title> Scripttype= "Text/javascript">document.getElementById ("Panel"). onclick= function() {alert ("The element has been loaded!"); } /*Execution Error*/ Script>Head>Body>DivID= "Panel">Click Me.Div>Body>HTML>If so, the binding event is not waiting for the element to
Original
$ ("# Qrcode "). on ("LOAD", function () {$ (". loading "). hide (); alert (1) ;}// or document. getelementbyid ("qrcode "). onload = function () {$ (". loading "). hide (); alert (1 );}
It seems that there is no problem, but why is onload often not called in IE? Because the browser caches images, the second
cannot be written at the same time and cannot be correctly executed: window. onload = function () {alert ("caibaojian") ;}; window. onload = function () {alert ("caibaojian.com") ;}; only the second
You can write the following code correctly: $ (document ). ready (function () {
elements are loaded, some methods can be executed. For example, some images or other aspects have not been loaded. At this time, clicking some buttons will lead to unexpected situations, at this time
Use:
The Code is as follows:
$ (Window). load (function (){$ ("# Btn-upload"). click (function () {// For example:UploadPhotos ();});});
Below is the reprinted content,Several reasons for using $ (window). load (function () {...}) instead of body. onload
$ (window). Load () method, which will wait until all the contents of the page have been loaded before triggering, and without the drawbacks of the onload event.The above code executes sequentially after all of the page's contents have been loaded.Of course, don't forget the Unload method that corresponds with it$ (window). Unload (function () {Alert ("Good Bye");});The above code is raised when the page c
Today I have studied the sequence of onload event execution for window objects,
First, add
Then add
The content of J. JS is as follows:
$ (Function (){
Alert ('document init ');
$ (Window). BIND ('load', function (){
Alert ('Bind load ');
});
});
Window. onload = function (){
executed in the order in which it was registered. Note that even the ready events that register different elements are executed in sequence.For example, the following code:$ (window). Ready (function () {Alert ("window");}); $ (document). Ready (function () {alert ("document");}); $ ("div"). Ready (function () {alert ("div");});650) this.width=650; "src=" Http:/
My initial code is as follows:
VaR IMG = new image;IMG. src = "test.gif ";IMG. onload = function (){Alert (IMG. width );};
This code is okay, but why is onload not called by IE? Because ie caches the image and loads the image 2nd times, instead of being uploaded from the server, but from the buffer. Isn't the onload
This article mainly introduces windows. onload () and $ (document ). ready () difference after the browser loads the DOM, it adds events to the DOM element through javascript. In javascript, window is usually used. onload () method.
In jquery, the $ (document). ready () method is used. The following describes the differences between the two.
Window. onlo
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.