Javascript在IE8中不起作用

时间:2023-01-17 13:11:12

The following JavaScript works on IE7 but not on IE8:

以下JavaScript适用于IE7,但不适用于IE8:

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

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

关于为什么会这样,以及如何克服它的任何建议。

7 个解决方案

#1


Have you tried:

你有没有尝试过:

onclick="history.back()"

with the quotes?

报价?


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

而且,回应你的声明它不起作用:au contraire,mon ami。

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

使用文件x1.html在我的IE8安装上运行正常以下两个文件:

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

当我加载x1时,我可以通过链接移动到x2,然后按钮移回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.

要使其工作,我必须做的一件事是转到工具 - > Internet选项 - >高级 - >安全性,然后选择允许活动内容在我的电脑上的文件中运行,所以几乎可以肯定你的浏览器中的安全设置是让你悲伤。

#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

我也有这个问题。永远不要在ie7上检查它也是一样的

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

以下代码无法在IE8上运行。可以在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.

您需要将history.back()放入您的href标记以及onclick事件中。

#5


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

尝试history.back(),如果这不起作用,那么试试这个history.back();返回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.

这不是答案,但也许它会帮助其他人挖掘真正的答案......问题可能与IE8的兼容模式有关。基于网页的DOCTYPE,IE8中发生了奇怪的事情。如果您的DOCTYPE是Transitional,IE8可能无法正确处理onclick事件。

#1


Have you tried:

你有没有尝试过:

onclick="history.back()"

with the quotes?

报价?


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

而且,回应你的声明它不起作用:au contraire,mon ami。

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

使用文件x1.html在我的IE8安装上运行正常以下两个文件:

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

当我加载x1时,我可以通过链接移动到x2,然后按钮移回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.

要使其工作,我必须做的一件事是转到工具 - > Internet选项 - >高级 - >安全性,然后选择允许活动内容在我的电脑上的文件中运行,所以几乎可以肯定你的浏览器中的安全设置是让你悲伤。

#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

我也有这个问题。永远不要在ie7上检查它也是一样的

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

以下代码无法在IE8上运行。可以在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.

您需要将history.back()放入您的href标记以及onclick事件中。

#5


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

尝试history.back(),如果这不起作用,那么试试这个history.back();返回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.

这不是答案,但也许它会帮助其他人挖掘真正的答案......问题可能与IE8的兼容模式有关。基于网页的DOCTYPE,IE8中发生了奇怪的事情。如果您的DOCTYPE是Transitional,IE8可能无法正确处理onclick事件。