简体   繁体   English

javascript:history.go(-1)在Internet Explorer 7中不起作用

[英]javascript: history.go(-1) not working in internet explorer 7

I am executing this line from a function -having this code only- that is called on onclick event on a link. 我正在从仅具有此代码的函数中执行此行,该函数在链接的onclick事件上被调用。

document.getElementById("backButton").href="javascript: history.go(-1);"

But this is not working for IE 7. Can anyone help me on this? 但这不适用于IE7。有人可以帮我吗? Here is the other part of code: 这是代码的另一部分:

<a id="backButton" title="Go Back To Previous Page"  href="./inmaking.html" 
    onclick="goBack();" onmouseover="status=''; return true;"
    style="background-color:#CCCC00;" >here</a> to go back to previous page.
location.href = document.referrer;

尝试以下方法:

<a id="backButton" title="Go Back To Previous Page" href="javascript:history.go(-1)" onmouseover="status=''; return true;" style="background-color:#CCCC00;" >here</a> to go back to previous page.

Your link has a default href value. 您的链接具有默认的href值。 To prevent the browser from entering it, you need to add return false; 为了防止浏览器进入,您需要添加return false; to end of the onclick . onclick结束。

onclick="goBack(); return false;"

Needless to say that stepping in browser history using JS like that is a poor practice. 不用说,像这样使用JS进入浏览器历史记录是一个糟糕的做法。 Rather store the last requested URL in the session scope or as a hidden input field and finally dynamically populate the link's href with that using whatever serverside language you're using. 而是将最后一个请求的URL存储在会话范围中或作为隐藏的输入字段,最后使用所使用的任何服务器端语言动态地使用该链接填充href

这对我有帮助:

 history.back();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM