JavaScript 当用户单击页面上的任意位置时触发 window.open
我有一个问题,我一直试图解决,但一直无法解决,因为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果用户阻止弹出窗口,那是因为他们不希望出现像您这样的弹出窗口作为对其用户交互的响应。如果您确实必须拥有弹出窗口(而不是更复杂的内容,例如显示隐藏的 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!-).