Chris Moodley
Chris Moodley

Reputation:

Javascript does not work in IE8

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.

Upvotes: 3

Views: 22063

Answers (7)

James K
James K

Reputation: 925

I had the same problem and solved it like this...

 <a href='javascript:history.back(); ' onclick="history.back(); "><input type="button" value="Back" /></a>

You need to put history.back() into your a href tag and also the onclick event.

Upvotes: 1

mostafa hk
mostafa hk

Reputation: 61

i used this and works well :

<asp:Button ID="Back_BTN" runat="server" Text="بازگشت" 
onclientclick="javascript:history.back(1);return false;" />

Upvotes: 2

paxdiablo
paxdiablo

Reputation: 881113

Have you tried:

onclick="history.back()"

with the quotes?


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

The following two files run fine on my IE8 install, using the files x1.html:

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

and 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 compatibility 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.

Upvotes: 6

aa.
aa.

Reputation: 11

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>

Upvotes: 1

Dem
Dem

Reputation:

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.

Upvotes: 0

Azder
Azder

Reputation: 4728

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>"

Upvotes: 0

Bhushan Bhangale
Bhushan Bhangale

Reputation: 10987

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

Upvotes: 0

Related Questions