简体   繁体   English

Onclick javascript 使浏览器 go 返回上一页?

[英]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.

相关问题 防止浏览器后退按钮不转到上一页 - Prevent browser back button to not go to previous page 在 Vue 中,如何使用 window.history.go(-1) 使浏览器到 go 返回上一页 - In Vue, how to make browser to go back to previous page using window.history.go(-1) 当按下浏览器后退按钮(在 Javascript 中)时,如何将特定变量传递给 go 返回上一页? - How to pass a specific variable to go back to the previous page when the browser back button is pressed (In Javascript)? onClick 按钮返回上一页/组件 React - onClick button to go back to previous page/component React 返回下一个/上一个div javascript onclick事件 - Go back to a next/previous div javascript onclick event 返回上一页 - Go Back to Previous Page 如何使“返回分页”按钮返回到上一个分页页面 - How to make the back to pagination button go back to previous pagination page 我需要使用浏览器按钮返回上一个动态页面 - I need to use the browser button to go back to the previous dynamic page 返回上一页状态而不是Javascript中的当前页面状态 - Go back on Previous page state not current Page State in Javascript 单击浏览器的“后退”按钮时,返回上一页的上一个位置 - Go Back to the Previous Location on Previous Page when Clicking Browser Back Button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM