如何使用JavaScript来触发浏览器的后退事件/函数? [英] How to trigger browser's back event/function using JavaScript?

查看:730
本文介绍了如何使用JavaScript来触发浏览器的后退事件/函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过我的页面模板的超链接触发浏览器的后退功能,使用JavaScript(或PHP如果可能的话)。有谁知道如何实现这一点?

I want to trigger the browser's back functionality through a hyperlink in my page template, using JavaScript (or PHP if possible). Does anyone know how to implement this?

修改结果
发现使用JavaScript的解决方案。这里是链接如果有人需要它...结果
http://www.sightspecific.com/~mosh/WWW_FAQ/back.html

和这里的code:结果
< A HREF =#的onClick =history.back();返回false;>返回< / A>

And here's the code:
<A HREF="#" onClick="history.back();return false;">Go back</A>

谢谢!

推荐答案

history.back()应该做的伎俩。

history.back() should do the trick.

window.history.back()文档

window.history.back() documentation at MDN

顺便说一句,这是不好的用户体验,如果你做这个意外的用户。例如,我在一个无效的信用卡号码输入,你带我回去一个页面,而不是让我修的错误。

As an aside, it's bad user experience if you do this unexpectedly on the user. For example, I enter in an invalid credit card number, and you take me back one page, instead of letting me fix the mistake.

因此​​,虽然可以使用JavaScript来操纵历史堆栈,这是更好地只能这样做,如果它在上下文中有意义当前用户的操作。

So while it's possible to use javascript to manipulate the history stack, it's better to only do so if it makes sense in the context current users actions.

这篇关于如何使用JavaScript来触发浏览器的后退事件/函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆