如何防止浏览器阻止我创建的弹出窗口? [英] How do I prevent browsers from blocking the pop-up window that I've created?

查看:60
本文介绍了如何防止浏览器阻止我创建的弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I created a simple JavaScript function to display my pop-up window once it loads. But it keeps on being blocked by Firefox and Google Chrome and I have to somehow enable it on the Firefox and Chrome to display the pop-up.

有其他选择吗?

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

I have a player on the pop-up window so I have to use a pop-up to let the player play automatically. The problem is that if I put it on the page itself, once the user clicks another page the entire page reloads and the player automatically stops for a few seconds until the whole page reloads and I have to prevent this from happening.

推荐答案

一般规则是,如果从未由直接用户操作调用的javascript中调用 window.open 或类似代码,则会启用弹出窗口阻止程序.也就是说,您可以调用 window.open 来响应按钮单击,而不会被弹出窗口阻止程序击中,但是如果将相同的代码放入计时器事件中,它将被阻止.呼叫链深度也是一个因素-一些较旧的浏览器仅查看直接呼叫者,较新的浏览器可以稍微回溯以查看呼叫者的呼叫者是否是鼠标单击等.请尽量使其浅,以免出现弹出窗口阻止程序.

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的答案.它涵盖了您的问题.

Please take a look at dthorpe's answer here. It covers your question.

这篇关于如何防止浏览器阻止我创建的弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆