阻止与非阻止弹出窗口

发布于 2024-08-12 18:26:16 字数 103 浏览 2 评论 0原文

我发现,浏览器不会阻止所有弹出的 JavaScript 窗口。

如何用JavaScript编写不会被浏览器拦截的弹出窗口?

我的意思是造成差异的主要因素是什么?

I found that, browsers don't block all pop-up JavaScript windows.

How to write pop-up windows in JavaScript that won't be blocked by browsers?

I mean what is the main factor that makes the difference?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柳絮泡泡 2024-08-19 18:26:16

在 Firefox(以及大多数其他带有弹出窗口拦截器的现代 Web 浏览器)中,如果用户单击 JavaScript 窗口,则通常会允许它们,但如果它们尝试在后台打开,则会停止。

将这些不良弹出窗口与这些好的弹出窗口。源代码可在网站上找到。这是“好”弹出窗口的源代码:

<a href="javascript:winopen('http://www.popuptest.com/popup3.html','blank','width=450,height=235,status=yes')">Good PopUp #1</a>
<br><br>
<A class=blu HREF="http://www.popuptest.com/popup2.html" target="_BLANK">Good PopUp #2</A>
<br><br>
<A class=black HREF="http://www.popuptest.com/popup3.html" onclick="NewWindow(this.href,'rank','450','450','yes','center');return false" onfocus="this.blur()">Good PopUp #3</A>
<br><br>
<a href="javascript:PopWindow('http://www.popuptest.com/popup4.html', 450, 320)">Good PopUp #4</A>

In Firefox (and most other modern web browsers with popup blockers) Javascript windows are typically allowed if they are the result of a user click, but stopped if they are trying to open in the background.

Compare the method used in these bad popups with these good popups. Source code is available on the site. Here is the source code for the "good" popups:

<a href="javascript:winopen('http://www.popuptest.com/popup3.html','blank','width=450,height=235,status=yes')">Good PopUp #1</a>
<br><br>
<A class=blu HREF="http://www.popuptest.com/popup2.html" target="_BLANK">Good PopUp #2</A>
<br><br>
<A class=black HREF="http://www.popuptest.com/popup3.html" onclick="NewWindow(this.href,'rank','450','450','yes','center');return false" onfocus="this.blur()">Good PopUp #3</A>
<br><br>
<a href="javascript:PopWindow('http://www.popuptest.com/popup4.html', 450, 320)">Good PopUp #4</A>
俯瞰星空 2024-08-19 18:26:16

决定阻止哪个弹出窗口的主要因素是良好的弹出窗口必须在用户执行某些操作(例如单击或执行其他事件(例如按 Enter)后显示)。

但是,您可以使用页内弹出窗口,例如 JQuery UI 对话框,所有弹出窗口拦截器无法拦截它,因为它只是像 span 或 div 这样的 html 标签。因此,它对于理解弹出标签内的内容不够聪明。这应该是避免所有弹出窗口阻止程序的最佳方法。

The main factor for deciding what popup window will be blocked is the good pop-up window must be show after user do some action like click or do some other event like press enter.

However, you can use in-page pop-up window like JQuery UI Dialog that all pop-up blocker cannot block it because it just is html tag like span or div. Therefore, it does not clever enough for understanding content inside pop-up tag. It should be the best way to avoid all pop-up blockers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文