0
當用戶通過瀏覽器的返回按鈕離開頁面時,我想從類(jsf bean)調用方法。我試圖使用window.onbeforeunload,但它適用於所有情況。例如,當用戶通過鏈接或按鈕重定向時。我怎樣才能讓它只是爲了後面的行動?如何識別html頁面中的後退動作?
當用戶通過瀏覽器的返回按鈕離開頁面時,我想從類(jsf bean)調用方法。我試圖使用window.onbeforeunload,但它適用於所有情況。例如,當用戶通過鏈接或按鈕重定向時。我怎樣才能讓它只是爲了後面的行動?如何識別html頁面中的後退動作?
你需要的是歷史API。
https://developer.mozilla.org/en-US/docs/Web/API/History_API
window.onpopstate = function(event) {
console.log("location: " + document.location + ", state: " + JSON.stringify(event.state));
};
看看[鏈接](https://developer.mozilla.org/en-US/docs/Web/Events/popstate) –