JS implementation Off Webpage Do you leave prompt?

js实现关闭网页出现是否离开提示

Whether you often encounter when it is closed, you will see a prompt box that determines whether to leave the current page? Think about some online testing systems, information entry system, often there will be some prompts, avoiding users intentionally or unintentionally turned off the page, resulting in data loss. The implementation process in this is simple, using the ONNLOAD and ONBEFOREUNLOAD methods in the HTML DOM event.

Definition: Perform a JavaScript when the user is unloaded, for example:

 / / body  // window 
window.onbeforeunload = function (e) { var e = window.event || E;
E.RETURNVALUE = "Determining the current page?");
}

Usage: When the user leaves the page, UNLOAD events will occur. Note: If you overload the page, UNLOAD events (and the OnLoad event) will also be triggered.

Turn off:
Turns off the browser window When you go to other pages, click to return, advance, refresh, home on one of the URL connections to other pages. When calling any of the following events: Click, Document Write, Document Open, Document Close, Window Close, Window Navigate, Window Navigate, Location Replace, Location Reload, Form Submit. When you open a page with Window Open, and put this Page WindoThe name of W is transmitted to the page to open. When re-imparts the value of Location.href. Submit a form with a specified action by the input type = “submit” button. OnBeforeunload Event Attribute
Definition: JavaScript is performed when the current page (refresh or off) is about to leave, for example:

// body

// window

window.onbeforeunload = function (e) {
var E = window.event || E; E.RETURNVALUE = (“OK Determine Leave the current page?”);
 }  

Onbeforeunload event is triggered when it is about to leave the current page (refresh or off). This event can be used to pop up dialogs, prompting the user to continue to browse the page or leave the current page. The default prompt information is different according to different browsers, and the standard information is similar to "Is it necessary to leave this page?". This information cannot be deleted. But you can customize some messages prompts to display the standard information in the dialog. Note: In the Firefox browser, only the default reminder information (no custom information is displayed).

Turn off:
Turns off the browser window When you go to other pages, click to return, advance, refresh, home on one of the URL connections to other pages. Time to call any of the following events: Click, Document Write, Document Open, Document Close, Window Close, Window Navigate, Window Navigatefind, Location Replace, Location Reload, Form SuUse Window Open to open a page and pass the name of the Window's name to the page you want to open. When re-imparts the value of Location.href. Submit a form with a specified action by the input type = "submit" button.

At present, the mainstream browser supports these two event properties

Overview

ONUNLOAD All ONBEFOREUNLOAD is called when refreshing or closing, and can be specified in

scripts or specified in

. The difference is that OnBeforeunload is executed before ONUNLOAD, it can also block the execution of ONUNLOAD. Onbeforeunload is also called when the page is refreshed or closed, and OnBeforeunload is called when it is going to read the new page. At this time, I haven’t started reading; and ONUNLOAD has read the new page that needs to be loaded from the server, which is about to replace Call when you dropped the current page. ONUNLOAD is unable to block the update and close of the page, and Onbeforeunload can do it.

js实现关闭网页出现是否离开提示

Only executing OnLoad

page is closed, onbeforeunload, last onunload

when refreshed Execute OnBeforeunload, then Onunload, last online

to attach part of the renderings:

Code of binding the Body tag:


Test

Function Checkleave () {EVENt.ReturnValue = “Determine?”;}
  Test      Google Browser Effect:   Click the refresh button:   Click the return button:    
through the taskbar or Favorites to other interfaces:

Close page:

js实现关闭网页出现是否离开提示 Effect under Edge:

Click the refresh button:

js实现关闭网页出现是否离开提示 Click the return button:

js实现关闭网页出现是否离开提示 Close page:

Note: In the new version of Firefox browser (I used to version: 57.0), this kind of way is not effective? ! js实现关闭网页出现是否离开提示

Test js实现关闭网页出现是否离开提示

Window.Onbeforeunload = function (e) {var e = window.event || E; E.RETURNVALUE = (“OK OK leave the current page?”);}

Test js实现关闭网页出现是否离开提示

js实现关闭网页出现是否离开提示 Firefox’s effect:

Click Refresh button:

Click the return button:
    Close page:      Note: This method is still applicable to Google, and the EDGE browser is still applicable, the effect is the first one!                      
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment