Home >Web Front-end >JS Tutorial >JavaScript monitors WeChat browser and comes with return button time
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", "#"); }
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