webkit/Chrome history.back(-1) onclick vs href [英] webkit / Chrome history.back(-1) onclick vs href

查看:25
本文介绍了webkit/Chrome history.back(-1) onclick vs href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人都知道,但我会重复这个问题:

Everybody knows that but I'll repeat the problem:

<a href="#" onClick="history.go(-1)">Back</a>

不适用于基于 WebKit 的浏览器(Chrome、Safari、Mxthon 等)

Will not work in WebKit based browsers (Chrome, Safari, Mxthon, etc.)

另一种不起作用的方法(应该有效)是:

Another approach (should work) that won't work is:

<a href="#" onclick="javascript:window.history.back(-1);">Back</a>

您可以这样做 - 有效!(但那是在 url 提示中显示 JS)

You could do this - works! (but that's showing JS in url hint)

<a href="javascript:window.history.back(-1);">Back</a>

要在 onclick 事件中使用 JS,您可以这样做(有效,但请参阅下面的评论):

To use JS in onclick event you could do this (works, but see comments below):

<a onclick="javascript:window.history.back(-1);">Please try again</a>

缺少 href 会使其工作,但不会显示为可点击链接,您可以应用 css 使其看起来像链接,应用蓝色、下划线和光标手,但谁想要呢?

Missing href will make it work, but then it won't appear as clickable link, you could apply css to make it look like link, apply blue color, underline and cursor hand, but who wants that?

推荐答案

终于可行的解决方案,在 IE、FF、Safari、Chrome、Opera、Maxthon 中测试:

Finally working solution, tested in IE, FF, Safari, Chrome, Opera, Maxthon:

<a href="#" onclick="window.history.back();return false;">Back</a>

return false 后不要忘记分号;

Don't forget semicolon after return false;

这篇关于webkit/Chrome history.back(-1) onclick vs href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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