Javascript does not work in IE8

二次信任 提交于 2020-01-24 09:34:06

问题


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.


回答1:


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.




回答2:


i used this and works well :

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



回答3:


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>



回答4:


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.




回答5:


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




回答6:


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



回答7:


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.



来源:https://stackoverflow.com/questions/754907/javascript-does-not-work-in-ie8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!