是什么导致某些浏览器将我的代码视为未经请求的代码?
我有一个网站致力于帮助人们进行交互式 session 。它从用户单击 [开始] 开始,因此这是一个同意的操作。这应该 (1) 打开一个弹出窗口,同时 (2) 将第一页重定向到结束页面,如下所示:
<head>
<SCRIPT language="JavaScript">
function openwindow(){window.open("{INTERACTION}","interaction","resizable=0,width=800,height=600,status=0");}</SCRIPT>
</head>
<body>
<FORM action="end.php" method="{METHOD}" >
<input type="submit" class="button"
onClick="javascript: openwindow()"
value="Begin" />
</FORM>
</body>
如前所述,这并不是试图打开一个未经请求的弹出窗口,但 IE 和 Chrome 的一些变种似乎正在这样对待它。我一直在尝试修复,最近消化了 this post .
里面有Bobince评论
these days, you don't really need to ask the question “was my unsolicited popup blocked?”, because the answer is invariably “yes” — all the major browsers have the popup blocker turned on by default. Best approach is only ever to window.open() in response to a direct click, which is almost always allowed.I'm quite happy to buy into this principle because I simply want my popup to open.
是什么导致某些浏览器将我的代码视为未经请求的代码?
如果您能给我任何帮助,我将不胜感激。 (正如您可能已经猜到的那样,客户端不是我的包,这个话题已经困扰我很久了)。
非常感谢(并祈祷) 吉尔斯
最佳答案
你无能为力。您可以要求您的用户禁用弹出窗口阻止程序,或者通过检查 window.open() 返回的窗口对象引用来通知他们弹出窗口阻止程序已启用
例如
var w = window.open('http://domain.com');
if(!w) {
//an alert in this example
alert('oops..seems like a pop-up blocker is enabled. Please disable');
}
您可以找到另一种方法并尝试 Brad 建议的方法。
关于javascript - 合法地避免弹出窗口阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6192889/