問題:H5頁面的返回鍵可以回退到指定頁面,但是Android手機的物理返回鍵會回到上一頁。
解決辦法:以下代碼可以實現,Android返回鍵時調用H5的方法(下面代碼中用的是H5的GoBackUrl方法),實現跳轉到指定頁面。
//攔截安卓回退按鈕,調用H5的返回方法 history.pushState(null, null, location.href); window.addEventListener('popstate', function (event) { history.pushState(null, null, location.href); GoBackUrl();//H5自己定義的返回方法 });
參考文檔:
https://www.cnblogs.com/hellxz/p/7764932.html