history.go(-1) going back doesnt work in Chrome
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.
精彩评论