Guest User

Untitled

a guest
Jan 23rd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. /**
  2. * Description: 监测 PC 端浏览器返回事件 & Android 返回事件
  3. * Author: Christina
  4. * Date: 2019-01-23
  5. **/
  6.  
  7. window.backConfirmed = false;
  8. pushHistory();
  9.  
  10. window.addEventListener("popstate", function(e) { //popstate监听返回按钮
  11. if(window.backConfirmed) {
  12. window.history.go(-1)
  13. } else {
  14. window.backConfirmed = false;
  15. window.history.pushState({}, "quit", "");
  16. confirm('确认离开么?')
  17. }
  18. }, false);
  19.  
  20. function pushHistory() {
  21. var state = {
  22. title: "myCenter",
  23. url: ""
  24. };
  25. window.history.pushState(state, state.title, state.url);
  26. }
Add Comment
Please, Sign In to add comment