Home > Web Front-end > JS Tutorial > JavaScript monitors WeChat browser and comes with return button time

JavaScript monitors WeChat browser and comes with return button time

高洛峰
Release: 2016-12-05 09:56:40
Original
1247 people have browsed it

For example, there is an operation now: A->B->C->B. The return key on page B returns C for the first time. If you want to return directly to A or other places, you need to trigger the return event

pushHistory(); 
   window.addEventListener("popstate", function(e) { 
     //alert("我监听到了浏览器的返回按钮事件啦");//根据自己的需求实现自己的功能 
     window.location = 'http://www.baidu.com';
   }, false); 
   function pushHistory() { 
     var state = { 
       title: "title", 
       url: "#"
     }; 
     window.history.pushState(state, "title", "#"); 
   }
Copy after login

Above The above is the JavaScript that the editor introduced to you to monitor the WeChat browser and comes with a return button time. I hope it will be helpful to everyone

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template