The JavaScript page load event

A, onload load event

  onload event is a window object, the window can also be used directly omitted.

  Common ways :

<head>
<script> windown.onload = function() { // 方法体 } </script>
<head>

   This event is completed after waiting for a page to load, and then execute the contents of <script> tag. That is, all the elements on the page is created, and references to external resources downloaded (js, css, pictures)

   Note : This event compared to the <body> of the <script> tag content in the slow speed of execution, because onload need to wait until the page is loaded executed, and the other elements on the page is created when will perform.

  onload not only can be applied to window, it can also be used for some other label.

Two, onunload unload event

  onunload event is uninstalled when uninstalling the page execution.

  Demo:

= The onunload. 1 function () {
 2 Alert ( 'Welcome to come again' ); // given:. Blocked alert ( 'Welcome to come again') During the unload
 . 3 the console.log ( 'BYE BYE' );
 . 4}

 

  When we press F5 to reload the page will find the alert dialog box will complain, and will not be executed, because the onunload event in all dialog boxes are not available, window objects are frozen.

    

 

Guess you like

Origin www.cnblogs.com/niujifei/p/11441746.html