简体   繁体   中英

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.

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.

i used this and works well :

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

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.

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>

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.

尝试history.back(),如果这不起作用,那么试试这个history.back();返回false;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM