[英]Onclick javascript to make browser go back to previous page?
Is there a function I can attach as a click event of a button to make the browser go back to previous page?是否有 function 我可以附加为按钮的单击事件以使浏览器 go 返回上一页?
<input name="action" type="submit" value="Cancel"/>
Add this in your input element将此添加到您的输入元素中
<input
action="action"
onclick="window.history.go(-1); return false;"
type="submit"
value="Cancel"
/>
history.back()
or或者
history.go(-1)
Put this to the button onclick
handle.把它放到按钮onclick
句柄上。 It should look like this:它应该是这样的:
<input name="action" onclick="history.back()" type="submit" value="Cancel"/>
For Going to previous page前往上一页
First Method第一种方法
<a href="javascript: history.go(-1)">Go Back</a>
Second Method第二种方法
<a href="##" onClick="history.go(-1); return false;">Go back</a>
if we want to more than one step back then increase如果我们想后退不止一步,那么增加
For going 2 steps back history.go(-2)
For going 3 steps back history.go(-3)
For going 4 steps back history.go(-4)
and so on.......
<input name="action" type="submit" value="Cancel" onclick="window.history.back();"/>
Shortest Yet!最短的!
<button onclick="history.go(-1);">Go back</button>
http://jsfiddle.net/qXrbx/ http://jsfiddle.net/qXrbx/
I prefer the .go(-number)
method as then, for 1 or many 'backs' there's only 1 method to use/remember/update/search for, etc.我更喜欢.go(-number)
方法,因为对于 1 个或多个“backs”,只有一种方法可以使用/记住/更新/搜索等。
Also, using a tag for a back button seems more appropriate than tags with names and types...此外,使用标签作为后退按钮似乎比带有名称和类型的标签更合适......
window.history.back(); window.history.back();
<button onclick="goBack()">Go Back</button>
<script>
function goBack() {
window.history.back();
}
</script>
Simple.简单的。 One line.一条线。
<button onclick="javascript:window.history.back();">Go Back</button>
Like Wim's and Malik's answer, but just in one line.就像 Wim 和 Malik 的回答一样,但只是在一行中。
您只需要调用以下内容:
history.go(-1);
Works for me everytime每次都对我有用
<a href="javascript:history.go(-1)">
<button type="button">
Back
</button>
</a>
This is the only thing that works on all current browsers:这是唯一适用于所有当前浏览器的方法:
<script>
function goBack() {
history.go(-1);
}
</script>
<button onclick="goBack()">Go Back</button>
the only one that worked for me:唯一对我有用的:
function goBackAndRefresh() {
window.history.go(-1);
setTimeout(() => {
location.reload();
}, 0);
}
访问window.history
然后back()
window.history.back()
history.back()
history.go(-1)
window.history.back()
100% 工作
<a onclick="window.history.go(-1); return false;" style="cursor: pointer;">Go Back</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.