1.HTML5 History Object
Supports using the Pushstate () method to modify the address bar address without refreshing the page.
Popstate Events
The Popstate event will occur when the history entity is changed. Invoking the Pushstate () method or the Replacestate () method is triggered when the user clicks the browser return button.
Event Registration instance:
function (event) { console.info (event); Console.info (event.state); Console.info (event.state.id);});
2. According to this event, if the trigger is to re-add the current page state, so that the user through the return button will not be able to leave the page.
This allows the return button to be locked in a state
<DivID= "Number"></Div><Script>pushhistory (); var Number=0; Window.addeventlistener ("popstate", function(e) {//alert ("I hear the browser's Return button event");//implement your own functions according to your needs Number++; varP=Document.createelement ('P'); P.innerhtml=Number ; document.getElementById (' Number'). appendchild (P); Pushhistory (); //note, called here, can the user stay on this page }, false); functionpushhistory () {var State={title:"title", URL:"#" }; Window.history.pushState (state,"title", "#"); }</Script>
More:
HTML5 History object, JavaScript modifies the address bar without refreshing the page
HTML5 History object, JavaScript modifies the address bar without refreshing the page (ii)
HTML5 geolocation API Geo-location finishing (ii)
HTML5 Browser Back button/Phone Back button event listener