JavaScript 当用户单击页面上的任意位置时触发 window.open

发布于 2024-08-31 16:29:13 字数 284 浏览 6 评论 0原文

我有一个问题,我一直试图解决,但一直无法解决,因为 Chrome/FireFox/IE 没有公开发布他们的 JavaScript、Flash 等弹出窗口阻止“规则”。当用户单击页面上的任意位置时,我试图触发 window.open() 。我已经尝试过:

document.onclick = window.open("http://msn.com");

但所有 3 个浏览器都会阻止弹出窗口,即使这是用户交互。

I have a problem that I have been trying to figure out and haven't been able to get past it because Chrome/FireFox/IE do not publicly publish their "rules" for pop up blocking when it comes to JavaScript, Flash, etc. I am trying to trigger a window.open() when a user clicks anywhere on page. I've tried this:

document.onclick = window.open("http://msn.com");

But all 3 browsers are blocking the popup, even though it is a user interaction.

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

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

发布评论

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

评论(1

寄风 2024-09-07 16:29:13

如果用户阻止弹出窗口,那是因为他们希望出现像您这样的弹出窗口作为对其用户交互的响应。如果您确实必须拥有弹出窗口(而不是更复杂的内容,例如显示隐藏的 div),则通知用户他们需要启用弹出窗口才能与您的网站进行交互(我见过一些网站这样做)这让我很恼火,我认为这是该网站的一个大黑点,促使我寻找他们的竞争对手和替代方案,但如果没有真正的替代方案,我会咬紧牙关,在这种情况下暂时重新启用弹出窗口) 。 (但是,一定考虑到烦人的用户并不是赢得他们的心的方法,所以一定寻找更好的替代方案!-)。

If the user is blocking pop-ups, it's because they don't want popups like yours to appear as a response to their user interactions. If a popup (as opposed to something more sophisticated such as making an otherwise hidden div appear) is what you really must have, then inform the user that they need to enable popups to interact with your site (I've seen a few sites do that, that annoys me and I count it as a big black mark against the site that prompts me to look for their competitors and alternatives, but if there's no real alternative I'll grit my teeth and temporarily re-enable popups in such cases). (But, do consider that annoying users is not a way to win their hearts and minds, so do look for nicer alternatives!-).

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