javascript 'window.open' 被 Firefox 阻止
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10471595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'window.open' blocked by Firefox
提问by Suneth Kalhara
I use window.open
and call it at the document ready
event, but it is blocked by a popup blocker in 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:
我window.open
在文档ready
事件中使用并调用它,但它被 Firefox 中的弹出窗口阻止程序阻止。然后我将它添加到函数中并从按钮调用此函数,然后触发按钮单击但没有成功:
$(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?
页面加载时,是否有某种方法可以在浏览器上打开外部弹出窗口或新选项卡?
采纳答案by Click Upvote
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 jQueryplugin like Colorboxto display a hovering modal window without opening a new popup, that the user can easily close.
另一方面,如果它是用户想要查看的消息,那么您可以使用像Colorbox这样的jQuery插件来显示悬停模式窗口,而无需打开新的弹出窗口,用户可以轻松关闭该窗口。
回答by demee
Firefox has a bunch of rules that helps it to decide whether popup should be blocked or not. 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 有一堆规则可以帮助它决定是否应该阻止弹出窗口。通常如果操作是通过用户点击初始化的,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:
即使打开了弹出窗口阻止程序。试试看: