简体   繁体   English

'window.open'被Firefox阻止

[英]'window.open' blocked by Firefox

I use window.open and call it at the document ready event, but it is blocked by a popup blocker in Firefox. 我使用window.open并在文档ready事件中调用它,但它被Firefox中的弹出窗口阻止程序阻止。 Then I added this to the function and make a call of this function from a button and then trigger the button click without success: 然后我将其添加到该函数并从按钮调用此函数,然后触发按钮单击而不成功:

$(function(){    
    abcd();    
});


function abcd(){
    var popup = window.open("http://localhost/johndyer-mediaelement-7ed6c51/demo/index.php","mypopup","width=500,height=300");       
 }

Is there some way to open an external popup window or new tab on browser when the page loaded? 当页面加载时,是否有某种方法可以在浏览器上打开外部弹出窗口或新选项卡?

Firefox has a bunch of rules that helps it to decide whether popup should be blocked or not. Firefox有一系列规则可以帮助它决定是否应该阻止弹出窗口。 Usually if action is initialized with user click, firefox will allow opening popup, but if it's done by "pure" javascript it will most likely block it. 通常如果使用用户点击初始化操作,firefox将允许打开弹出窗口,但如果它由“纯”javascript完成,则很可能会阻止它。

You can read about it in here: http://support.mozilla.org/en-US/kb/Pop-up%20blocker . 你可以在这里阅读: http//support.mozilla.org/en-US/kb/Pop-up%20blocker

So if you read article carefully you will notice that popups initialized by user click will open: 因此,如果您仔细阅读文章,您会注意到用户点击初始化的弹出窗口将打开:

<input type="button" value="Click Me"/>

and jquery code 和jquery代码

$('input').click(function(){window.open("http://google.com");​​​​})​

even with popup blocker turned on. 即使打开弹出窗口拦截器。 Try it: 试试吧:

http://jsfiddle.net/demee/mQ9eR/ http://jsfiddle.net/demee/mQ9eR/

Don't open pop up advertising. 不要打开弹出广告。 It's annoying. 它很烦人。

On the other hand, if it's a message the user wants to see, then you can use a jQuery plugin like Colorbox to display a hovering modal window without opening a new popup, that the user can easily close. 另一方面,如果它是用户想要看到的消息,那么您可以使用像Colorbox这样的jQuery插件来显示悬停模式窗口,而无需打开新的弹出窗口,用户可以轻松关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM