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


基础教程推荐
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01