在Chrome中点击两次,而不是IE或Firefox
Onclick firing twice in Chrome, not IE or Firefox
很抱歉重复了我的帖子为什么setTimeout在Chrome中触发了两次,而在IE或Firefox中却没有?。
实际上,我需要以下javascript调用来内联超链接,所以我想知道是否有人有任何想法。单击任一超链接都会导致javascript函数GenerateNewNumber在Chrome中触发两次,但IE或Firefox除外。一旦你在Chrome中点击了一次,它只会在随后的点击中添加到标签中一次。我再次使用Chrome 20.0.1132.57、IE9和Firefox 13。
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function GenerateNewNumber() {
var randomnumber = Math.floor(Math.random() * 1234);
document.getElementById('NumberLabel').innerHTML += '<br>' + 'Random Number is ' + randomnumber;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:LinkButton ID="Button1" runat="server" OnClientClick="GenerateNewNumber(); return false;">Click for Random Number Test 1</asp:LinkButton><br />
<a id="Button2" href="#" onclick="GenerateNewNumber(); return false;" target="_blank">Click for Random Number Test 2</a>
<asp:Label ID="NumberLabel" runat="server"></asp:Label>
</form>
</body>
</html>
再次感谢你的帮助。
这可能是您使用的谷歌扩展的结果。然而,我确实记得有过这个问题,并且在超链接的onclick中指定了return false。我记得一些普通的调整让它停止了两次发射。
请尝试删除"return false"后面的分号。
回顾这篇文章,asp。NET链接按钮在谷歌Chrome 中不起作用
你可以试试这个方法。
protected override void OnPreInit(EventArgs e)
{
if (Request.UserAgent != null && (Request.UserAgent.IndexOf("AppleWebKit") > 0)) // added for compatibility issues with chrome
{
this.ClientTarget = "uplevel";
}
base.OnPreInit(e);
}
最后,您应该考虑使用链接/锚点以外的元素/标记。
相关文章:
- 为什么这在IE中的工作方式与在Firefox中不同
- IE/Chrome中未定义的函数,但Firefox中没有
- 滚动在Chrome中有效,但在Firefox或IE中无效
- document.images未加载在chrome或firefox上,但已加载在IE上
- 为什么这个按钮在IE中有效,但在Firefox中无效
- 无法在IE、Firefox中使用adobeacrobat9pro调试PDF中的javascript
- 以下颜色更改功能在IE9和Firefox中运行良好,但在早期的IE或Chrome中则不然
- 通过单击主菜单外部关闭子菜单'不适用于IE,但适用于Firefox&铬
- jquery表单提交无法使用多个输入(IE和Firefox)
- Multi-platform (Chrome, IE, Firefox)
- contentEditable and lastChild IE, Firefox & Chrome LastC
- onblur事件在IE/Firefox/Chrome中有所区别
- Javascript代码关闭标签,适用于IE, Firefox和Chrome
- window.print()对话框在IE, Firefox和Safari中正常工作时,在Chrome中不显示
- IE/Firefox气泡事件
- MarginLeft不工作在IE/Firefox内的功能(但从控制台工作)
- 在IE/FireFox/Chrome中横向打印DIV
- 通过javascript的IE/Firefox样式更新不工作
- 在Chrome / Safari下载文件期间$ajax调用挂起,而不是在IE / Firefox中
- 如何在IE, Firefox和Chrome中使用谷歌网页字体