gpt4 book ai didi

javascript - 如何防止浏览器阻止我创建的弹出窗口?

转载 作者:行者123 更新时间:2023-11-28 01:42:44 25 4
gpt4 key购买 nike

我创建了一个简单的 JavaScript 函数来在加载后显示弹出窗口。但它一直被 Firefox 和 Google Chrome 阻止,我必须以某种方式在 Firefox 和 Chrome 上启用它才能显示弹出窗口。

有什么替代方案吗?

我在弹出窗口上有一个播放器,所以我必须使用弹出窗口让播放器自动播放。问题是,如果我将它放在页面本身上,一旦用户单击另一个页面,整个页面就会重新加载,播放器会自动停止几秒钟,直到整个页面重新加载,我必须防止这种情况发生。

最佳答案

The general rule is that popup blockers will engage if window.open or similar is invoked from javascript that is not invoked by direct user action. That is, you can call window.open in response to a button click without getting hit by the popup blocker, but if you put the same code in a timer event it will be blocked. Depth of call chain is also a factor - some older browsers only look at the immediate caller, newer browsers can backtrack a little to see if the caller's caller was a mouse click etc. Keep it as shallow as you can to avoid the popup blockers.

请在此处查看 dthorpe 的回答。它涵盖了您的问题。

关于javascript - 如何防止浏览器阻止我创建的弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24947152/

25 4 0
文章推荐: html - 如何获取 html/css 表单以发布到 Gravity Forms?
文章推荐: Javascript:为 FileReader readAsBinaryString 准备图像对象
文章推荐: javascript - 火狐扩展开发 : How to set an observer only once
文章推荐: html - XPath 选择该父 div 内的