tags:

views:

133

answers:

2

I am executing this line from a function -having this code only- that is called on onclick event on a link.

document.getElementById("backButton").href="javascript: history.go(-1);"

But this is not working for IE 7. Can anyone help me on this? Here is the other part of code:

<a id="backButton" title="Go Back To Previous Page"  href="./inmaking.html" 
    onclick="goBack();" onmouseover="status=''; return true;"
    style="background-color:#CCCC00;" >here</a> to go back to previous page.
A: 

Try this instead:

<a id="backButton" title="Go Back To Previous Page" href="javascript:history.go(-1)" onmouseover="status=''; return true;" style="background-color:#CCCC00;" >here</a> to go back to previous page.
md5sum
nopes this too not working in ie
Rahul Utb
I just tested that verbatim in Chrome and IE8 and it works fine. There's no reason why it shouldn't work fine on IE7 as well, as I'm quite certain I've used that before. You should make sure that something else isn't covering the link or blocking the action.
md5sum
I am rid of ie but cann't do anything its widely spread... I made all setting again but this does't work in IE7 in chrome and FF even it works fine at my end
Rahul Utb
A: 

Your link has a default href value. To prevent the browser from entering it, you need to add return false; to end of the onclick.

onclick="goBack(); return false;"

Needless to say that stepping in browser history using JS like that is a poor practice. Rather store the last requested URL in the session scope or as a hidden input field and finally dynamically populate the link's href with that using whatever serverside language you're using.

BalusC
even this not working
Rahul Utb
Because it's a poor practice. You would be dependent on the client's environment and configuration. Rather do it from the server side on, that's more robust.
BalusC
I do agree, it may not be good practice. But I am using this for very very simple purpose. Not using ANY sever side scripting. only html, css and js and need to go just 1 step back.
Rahul Utb
Well, good luck with that. Try reinstalling IE7 :)
BalusC