我有一个表单,一旦提交,它会将用户带到“感谢页面”,其想法是,如果用户单击后退按钮,则不会返回表单,而是会将用户带到不同的页面。我正在使用 src="backfix.min.js"
,它正确地位于 .js 文件中。正在提醒该消息,但由于某种原因,它没有将用户带到我想要的页面。
<!DOCTYPE html>
<html>
<head>
<title>Thank You!</title>
<script type="text/javascript" src="backfix.min.js"></script>
<script type="text/javascript">// <![CDATA[
bajb_backdetect.OnBack = function()
{
alert("Will take you back to the main page");
document.location.href = 'http://goggle.com';
};
</script>
</head>
<body style="background-color: white" >
<div align="center" >
<img alt="thanyou" src="Images/thank_you[2].png" width="800" height="600">
</div>
</body>
</html>
最佳答案
浏览器后退按钮运行window.history.back()
。
因此,使用window.history.back
并覆盖它:
bajb_backdetect.OnBack = function()
{
alert("Will take you back to the main page");
window.history.back=function(){document.location='http://google.com';};
}
它对我有用,我知道我的意思是 back.fix
this Library
更新:
这是my example :
如果还不起作用。将所有代码包装在 setTimeout
函数中:
setTimeout(function(){
bajb_backdetect.OnBack = function()
{
alert("Will take you back to the main page");
window.history.back=function(){document.location='http://google.com'}
}
},200)
关于javascript - 单击后退按钮时重定向到不同页面 "not working",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23526385/