Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Description: 监测 PC 端浏览器返回事件 & Android 返回事件
- * Author: Christina
- * Date: 2019-01-23
- **/
- window.backConfirmed = false;
- pushHistory();
- window.addEventListener("popstate", function(e) { //popstate监听返回按钮
- if(window.backConfirmed) {
- window.history.go(-1)
- } else {
- window.backConfirmed = false;
- window.history.pushState({}, "quit", "");
- confirm('确认离开么?')
- }
- }, false);
- function pushHistory() {
- var state = {
- title: "myCenter",
- url: ""
- };
- window.history.pushState(state, state.title, state.url);
- }
Add Comment
Please, Sign In to add comment