还有另外一种方法:
<a href="javascript:history.back()">Go Back</a>
<button type="button" onclick="javascript:history.back()">返回</button>
- Leo此解决方案的好处在于在悬停时显示所链接页面的URL,就像大多数浏览器默认情况下所做的那样,而不是使用history.go(-1)
或类似方法:
<script>
document.write('<a href="' + document.referrer + '">Go Back</a>');
</script>
target="_blank"
属性而打开的情况,而 history.go(-1)
无法做到这一点。 - Chris Krychohistory.back() || "myaction/mycontroller"
。 - nestvar element = document.getElementById('back-link');
// Provide a standard href to facilitate standard browser features such as
// - Hover to see link
// - Right click and copy link
// - Right click and open in new tab
element.setAttribute('href', document.referrer);
// We can't let the browser use the above href for navigation. If it does,
// the browser will think that it is a regular link, and place the current
// page on the browser history, so that if the user clicks "back" again,
// it'll actually return to this page. We need to perform a native back to
// integrate properly into the browser's history behavior
element.onclick = function() {
history.back();
return false;
}
<a id="back-link">back</a>
return false;
,以防止它将当前页面添加到浏览器历史记录中。 - Marshall Morrise你可以尝试使用 JavaScript。
<A HREF="javascript:history.go(-1)">
编辑
为了显示引用的url,参考http://www.javascriptkit.com/javatutors/crossmenu2.shtml,并将元素a自身在onmouseover中发送如下内容。
function showtext(thetext) {
if (!document.getElementById)
return
textcontainerobj = document.getElementById("tabledescription")
browserdetect = textcontainerobj.filters ? "ie" : typeof textcontainerobj.style.MozOpacity == "string" ? "mozilla" : ""
instantset(baseopacity)
document.getElementById("tabledescription").innerHTML = thetext.href
highlighting = setInterval("gradualfade(textcontainerobj)", 50)
}
<a href="http://www.javascriptkit.com" onMouseover="showtext(this)" onMouseout="hidetext()">JavaScript Kit</a>
查看jsfiddle。
history.go(-1);
请尝试这个:
<a href="#" onclick="history.go(-1)">Go Back</a>
为了使用锚标签<a>
返回上一页,以下是两种可行的方法,其中第一种方法更快,并且在返回上一页时具有一个重要优势。
我已尝试过这两种方法。
1)
<a href="#" onclick="location.href = document.referrer; return false;">Go Back</a>
如果您点击链接并在当前浏览器窗口中以新标签页打开链接,则上述方法(1)非常有效。
2)
<a href="javascript:history.back()">Go Back</a>
如果您在当前浏览器窗口中单击链接并在当前标签页中打开链接,则上述方法(2)仅在这种情况下有效。
如果您在新标签页中打开链接,则它将无效。在Web浏览器的新标签页中打开链接时,history.back()
将不起作用。
反向链接是一种将浏览器后退一页的链接,就像用户在大多数浏览器中单击“后退”按钮一样。反向链接使用JavaScript。如果您的浏览器支持JavaScript(它确实支持),并且它支持window.history
对象,那么它将使浏览器后退一页。
简单的方法包括:
<a href="#" onClick="history.go(-1)">Go Back</a>
或者:
function goBack() {
window.history.back()
}
<a href="#" onclick="goBack()" />Go Back</a>
一般来说,后退按钮就足够了,而且通常你也可以简单地链接到站点中的上一页。但是,有时候您可能想要提供一个链接回到几个“之前”的页面之一,这时候后退链接就非常方便。因此,如果您想以更高级的方式进行操作,请参考下面的教程:
http://www.htmlcodetutorial.com/linking/linking_famsupp_108.html
<a href="javascript:history.go(-1)"> Go Back </a>
<a href="#" onclick="history.back();">Back</a>
href
的数量。我们可以使用#
! - mehmet使用按钮的最佳方式是
<input type= 'button' onclick='javascript:history.back();return false;' value='返回'>