When the user exits the page (page close, page refresh, and so on), the OnUnload event is triggered and the called program is executed.
Note: Different browsers have different support for onunload events.
The following code, when exiting the page, pops up the dialog box "Are you sure you want to leave this page?" ”。
650) this.width=650; "src=" http://img.mukewang.com/5312ee6b0001f89408950418.jpg "style=" Color:rgb (31,36,38); font-size:18px;font-weight:bold; "alt=" 5312ee6b0001f89408950418.jpg "/>
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>
Run Result: (IE browser)
650) this.width=650; "src=" Http://img.mukewang.com/546470c90001583205460464.jpg "alt=" 546470c90001583205460464.jpg "/>
Individual additions to the following points:
Browse the next page, I summed up the next, the wrong place a lot of advice
Uninstall event in layman's words, there are two ways to leave the current page and leave the current page.
1. As usual we close the page, that is to leave the page; 2. Click on the current page to load other pages, jump to other pages, but also to leave the current page;
OnUnload belongs to the 2nd type, only when you want to jump to another page, that is, to leave the current page, to jump to another page, onunload will be triggered;
How do you get out of a dialog box when you close the page in the usual way? There is also a onbeforeunload, as the name implies, is the onunload is executed before, is called, regardless of the above 2 kinds of jump method of which, onbeforeunload will be triggered.
2. a few notes:
① currently tried Firefox, Google Chrome, ie three browsers, the event only works for IE.
The ②onunload event is valid for refreshing pages and hyperlinks to other pages, and is not valid for closed pages.
The ③onbeforeunload event is only valid for the close page.
④window.onunload = Onunload_message does not need to be appended (). If someone does not add (), both in the page jump and refresh the prompt box, is because IE restricts the Web page run script or ActiveX control, click "Allow blocked Content", and then refresh and jump to see the effect.
⑤ added (), the page will pop up the prompt box, this is not the effect we want to achieve.
Window.onunload = onunload_message () Google brackets are used.
JavaScript Unload event (onunload)