手機端網頁處理手機返回鍵
阿新 • • 發佈:2019-02-11
// 手機端網頁: 處理手機返回鍵 window.onpopstate = function (event) { // 監聽到已經按下返回鍵,獲取URL var url = "" + document.location + ""; var returnDialog = dialog({ width : 260, content : '<p class="tc">確定放棄上傳商品?</p>', okValue : '確定', cancelValue : '返回', ok : function(){ window.history.go(-1詳細可檢視https://www.cnblogs.com/zhuchenglin/p/7607768.html); return true; }, cancel : function(){ history.pushState("x-back", null, location.href); //停留在當前頁面 return true; } }); returnDialog.showModal(); }; // 需要push一筆資料到history // history.pushState({'page':1}, "title", "XXXXXXXXXXX"); history.pushState("x-back", null, location.href);