[英]Redirect to another page on clicking the back button
When a user visits my page and clicks on the back button I want to redirect them to another page.当用户访问我的页面并单击后退按钮时,我想将他们重定向到另一个页面。 How can I do this?
我怎样才能做到这一点? This is in a simple PHP or HTML Web page.
这是在一个简单的 PHP 或 HTML Web 页面中。
if (window.history && window.history.pushState) {如果(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');
}
This code works on all updated browsers except internet explorer.此代码适用于除 Internet Explorer 之外的所有更新的浏览器。 For internet explorer JSBBQ library needs to be implemented and modified.
对于 Internet Explorer JSBBQ 库需要实现和修改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.