webkit / Chrome history.back(-1) onclick vs href(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:webkit/Chrome history.back(-1) onclick vs href


基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01