IOS micro-channel browser to return to the event listener questions

业务需求:从主页进入A订单页面,然后经过各种刷新或点标签加载后点左上角的返回直接返回到主页
采取方法:采用onpopstate事件监听url改变,从而跳转到主页
遇到的问题:安卓上测试没问题;苹果手机微信里进入A页面直接触发onpopstate返回主页,造成类似闪退现象,
给popstate监听事件addEventListener加延时后问题依旧,设置flag标志使popstate事件里的跳转函数加延时问题解决,
但是只是解决了从主页跳转到A页面的问题,A订单页面点订单跳转到订单详情B页面,从B页面返回A页面时出现了问题,
直接触发popstate的回调函数跳转到了主页,而没有留在A页面。目前只有IOS上的微信出现这个问题了,怎么解决?
In practical applications, we often need to achieve returns in the mobile app and click on the browser, back, etc. Back button to achieve their Close, adjusted to a specific page or perform some other operations 
needs, then how in the code click to listen when micro-channel, pay Po incident, Baidu glutinous rice, Baidu wallet app back button or browser's Back button or the back of it. 
 
I believe many of my friends like me, searching for a long time failed to find a way in Baidu, Sogou inside. Here to tell you how to monitor the method: 
 
 
First, we must understand the history of the browser. We all know that the page we can use javascript window history, back to the front page, but can not be modified for security reasons javascript 
history in the existing url link, but you can use pushState method to increase the url links in history, and provides event monitoring popstate url pop history from the stack. Since there is provided popstate event 
monitor, then we can listen. 
 
Return back, click the Back button monitor implementation code: 

window.addEventListener ( "the popstate", function (E) {   
        Alert ( "I listen to the browser's back button event friends"); // realize their own needs function   
    }, false);   

While we listen back to the event, but will return to the previous page or a page, so we need to use a pushState increase the page url, on behalf of the page, we are very clear that # 

 

function pushHistory () {   
        State = {var   
            title: "title",  
            URL: "#"   
        };   
        window.history.pushState (State, "title", "#");   
    }   

when entering the page, we give the history pressed into a local connection. When you click to return, back and previous operations, it listens, listens to achieve their operation in the code. 
Here is the complete code: 
// anonymous function 
$ (function () { 
   getHistory (); 
    var = In Flag to false; 
the setTimeout (function () { 
    In Flag to true = 
}, 1000) 
   window.addEventListener ( 'the popstate', function (E) { 
   // listen to return to the event 
    IF (Flag) { 
   // what you want to do 
      } 
    getHistory (); 
}, false);       
function getHistory () { 
   var State = { 
   title: '', 
   url: '// be write return jump path event '   
}; 
window.history.pushState (State,' title ', URL);
})

 



Guess you like

Origin www.cnblogs.com/1212dsa/p/11426122.html