Javascript 单击“后退”按钮时重定向到其他页面;“不工作”;
我有一个表单,一旦提交,它会将用户带到一个“感谢页面”。这个想法是,如果用户点击后退按钮,而不是返回表单,它会将用户带到另一个页面。我使用的是Javascript 单击“后退”按钮时重定向到其他页面;“不工作”;,javascript,html,Javascript,Html,我有一个表单,一旦提交,它会将用户带到一个“感谢页面”。这个想法是,如果用户点击后退按钮,而不是返回表单,它会将用户带到另一个页面。我使用的是src=“impfix.min.js”,它正确地位于.js文件中。正在提醒消息,但由于某种原因,它不会将用户带到我想要的页面 <!DOCTYPE html> <html> <head> <title>Thank You!</title> <script type="text/javascr
src=“impfix.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
更新:
这是:
如果还不起作用。将所有代码包装在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)
您可以尝试使用window.location.href
window.location.href
而不是document.location.href
来使用window.location.href。同样的情况也会发生:提醒消息,但当我单击“确定”时,会将我带回表单末尾的超时时间(200)是多少,第一个和这个有什么区别?它是200毫秒。等待所有JS对象就绪(即:window.history)只是一种预防措施。