![](/img/trans.png)
[英]Clicking the back button and landing on a page with a timeout redirect to the same page
[英]Redirect to another page on clicking the back button
當用戶訪問我的頁面並單擊后退按鈕時,我想將他們重定向到另一個頁面。 我怎樣才能做到這一點? 這是在一個簡單的 PHP 或 HTML Web 頁面中。
如果(window.history && window.history.pushState){
$(window).on('popstate', function() {
var hashLocation = location.hash;
var hashSplit = hashLocation.split("#!/");
var hashName = hashSplit[1];
if (hashName !== '') {
var hash = window.location.hash;
if (hash === '') {
alert('Back button was pressed.');
window.location='https://www.google.com/';
return false;
}
}
});
window.history.pushState('forward', null, './#forward');
}
此代碼適用於除 Internet Explorer 之外的所有更新的瀏覽器。 對於 Internet Explorer JSBBQ 庫需要實現和修改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.