webkit / Chrome history.back(-1)onclick vs href [英] webkit / Chrome history.back(-1) onclick vs href
问题描述
< a href =#onClick =历史。去(-1)>返回< / A>
不适用于基于WebKit的浏览器(Chrome,Safari,Mxthon等)。
另一种不起作用的方法是:
< a href =#onclick =javascript:window.history.back(-1);>返回< / a>
你可以这样做 - 工作! (但这是在url提示中显示JS)
< a href =javascript:window.history.back(-1) ;>返回< / A>
要在onclick事件中使用JS,你可以这样做(工作,但见下面的注释) p>
< a onclick =javascript:window.history.back(-1);>请再试一次< / a>
缺少href将使其工作,但它不会显示为可点击的链接,您可以应用css使它看起来像链接,应用蓝色,下划线和光标手,但谁愿意? 解决方案
最后的工作解决方案,在IE,FF,Safari,Chrome,Opera,Maxthon中测试:
< a href =#onclick = window.history.back();返回false;>返回< / a>
返回false后别忘了分号;
Everybody knows that but I'll repeat the problem:
<a href="#" onClick="history.go(-1)">Back</a>
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>
You could do this - works! (but that's showing JS in url hint)
<a href="javascript:window.history.back(-1);">Back</a>
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>
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?
Finally working solution, tested in IE, FF, Safari, Chrome, Opera, Maxthon:
<a href="#" onclick="window.history.back();return false;">Back</a>
Don't forget semicolon after return false;
这篇关于webkit / Chrome history.back(-1)onclick vs href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!