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
基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
