我创建了一个简单的 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 callwindow.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/