javascript - 单击后退按钮时重定向到不同页面 "not working"

标签 javascript html

我有一个表单,一旦提交,它会将用户带到“感谢页面”,其想法是,如果用户单击后退按钮,则不会返回表单,而是会将用户带到不同的页面。我正在使用 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/

相关文章:

javascript - 切换 body 背景

Javascript更改位置href并单击某个按钮

javascript - 更改 Img 中的数据缩放 HTML

html - 在图片css内容下添加文字

html - CSS 和 Entypo 字体播放效果不佳

PHP 登录保持登录状态( session )

html - 如何在 HTML 中多次使用 <br>

javascript - 用来自其他数组的对象填充一个数组

javascript - 使用 MIME 类型 application/json 可能会导致什么问题?

c# - 如何将此 javascript 函数放置在外部文件中以供用户控制?