views:

5705

answers:

5

The following JavaScript works on IE7 but not on IE8:

onclick=history.back(1) or history.go(-1)

Any suggestions on why this is the case and how to overcome it.

+5  A: 

Have you tried:

onclick="history.back()"

with the quotes?

Responding to your statement that it doesn't work: au contraire, mon ami.

The following two files run fine on my IE8 install:

x1.html
    <html><head></head><body>
        X1
        <hr>
        <a href="x2.html">x2</a>
    </body></html>

x2.html
    <html><head></head><body>
        X2
        <hr>
        <button onclick="history.back()">Back!</button>
    </body></html>

When I load x1, I can move to x2 with the link, then the button moves back to x1.

This works in all three compat-modes, ergo it must be a setting on your browser which is affecting this.

One thing I had to do to get this to work was to go to Tools -> Internet Options -> Advanced -> Security and select Allow active content to run in files on My Computer, so it's almost certainly a security setting in your browser which is causing you grief.

paxdiablo
Unfortunately, this does not work, Pax
Chris Moodley
A: 

Try history.back(), if that doesn't work then try this history.back();return false;

Bhushan
Hi BhushanUnfortunately, this does not work
Chris Moodley
A: 

It may be a simple reversal of quotes. Try this

lblmessage.Text += '<br><a href="#" onclick="history.back(1);"> <u>Back</u></a>'

instead of this

lblmessage.Text += "<br><a href='#' onclick='history.back(1);'> <u>Back</u></a>"
Azder
A: 

This isn't the answer, but maybe it will help someone else dig up the real answer... The issue might be related to IE8's compatibility mode. Weird things happen in IE8 based on the DOCTYPE of the web page. If your DOCTYPE is Transitional, IE8 might not properly handle the onclick event.

Dem
HTML 5 doctype wins. It forces every browser into standards mode.
apphacker
+1  A: 

I also had this problem. Never check its also the same on ie7 or not

Code like below cant run on IE8. Can on FF3.5

<select size="2">
<option onclick="alert('hey hey')">Hey hey</option>
<option onclick="alert('a ha')">A Ha</option>
</select>

However, this on work

<select onclick="alert('uh oh')" size="2">
<option>Hey hey</option>
<option>A Ha</option>
</select>
aa