开发者

history.go(-1) going back doesnt work in Chrome

开发者 https://www.devze.com 2023-01-06 00:40 出处:网络
href=\"#\" onclick=\"closeOrCancel() and history.go(-1) in that js method doesnt work in Chrome (ne开发者_JS百科ither history.back())

href="#" onclick="closeOrCancel() and history.go(-1) in that js method doesnt work in Chrome (ne开发者_JS百科ither history.back())

It works with href="javascript:closeOrCancel()" , but Opera doesn't allow href="javascript:...

How to make history go back using onclick= "myFunction()" ?

Edit: closeOrCancel() returns false


Adding a return false; to the onclick code seems to be enough:

<a href="#" onclick="closeOrCancel(); return false;">Go Back</a>


You're wrong about two things here:

  • Opera allows href="javascript:...
  • history.go(-1) works in Chrome.

Please provide source for your script, since the problem is clearly in it and not the browsers.

Just put this in a html file and open it to see for yourself:

<script>
function goback() {
    history.go(-1);
}
</script>
<a href="javascript:goback()">goback</a>
<a href="#ttttt">tt</a>

First click the "tt" link, then "goback". See the hash change. It works fine, although I'd personally recommend against using javascript in href's.


I used history.go(-2); to go back to step 1 in chrome.

0

精彩评论

暂无评论...
验证码 换一张
取 消