合法地避免弹出窗口阻塞 [英] Legally avoiding popup blocking

查看:81
本文介绍了合法地避免弹出窗口阻塞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么原因导致某些浏览器将我的代码视为未经请求的?

What is causing some browsers to see my code as unsolicited?

我有一个致力于帮助人们进行交互式会话的网站。它从用户单击[开始]开始,因此这是一个同意的操作。这应该(1)打开弹出窗口,同时(2)将第一页重定向到结束页面,如下所示:

I have a web site devoted to helping people with interactive sessions. It starts with the user clicking [Begin] so this is a consented action. This should (1) open a popup while (2) redirecting the first page to a end page as below :

<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的某些应变似乎这样对待它。我一直试图修复,最近消化这篇文章

As said, this is not trying to open an unrequested popup but some strains of IE and Chrome appear to be treating it as such. I have been trying to get a fix, most recently digesting this post.

在其中Bobince评论

In it Bobince comments


这些天,你真的不需要问一个问题我的未经请求的弹出窗口被阻止了吗?,因为答案总是是 - 所有主流浏览器都默认打开弹出窗口阻止程序。最好的方法是只对window.open()响应直接点击,这几乎总是允许的。我很乐意接受这个原则,因为我只想让我的弹出窗口打开。

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.

是什么原因导致某些浏览器将我的代码视为未经请求的?

What is causing some browsers to see my code as unsolicited?

我很感激你能给我的任何帮助。 (正如你可能已经猜到的那样,客户端不是我的包,而且这个主题一直困扰着我多年。)

I'd appreciate any help you could give me. (as you might have guessed, client side is not my bag and this topic has been bugging me for ages).

非常感谢提前(和手指交叉)
Giles

Many thanks in advance (and fingers crossed) Giles

推荐答案

你无能为力。你可以要求你的用户禁用弹出窗口阻止程序,或者通过检查window.open()返回的窗口对象ref来通知他们弹出窗口阻止程序已启用。

No much you can do. You could ask your users to disable pop-up blockers or inform them that a pop-up blocker is enabled by checking the window object ref returned by 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的建议。

you could find another way and try what Brad suggests.

这篇关于合法地避免弹出窗口阻塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆