'window.open' blocked by Firefox

22,679

Solution 1

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.

Solution 2

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.

You can read about it in here: 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

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

even with popup blocker turned on. Try it:

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

Share:
22,679
Suneth Kalhara
Author by

Suneth Kalhara

Updated on July 09, 2022

Comments

  • Suneth Kalhara
    Suneth Kalhara almost 2 years

    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:

    $(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?

  • demee
    demee about 12 years
    If I knew how to programmatically switch off user's poupup blockers I'd be millionaire. Maybe instead of using browser based popup try to use something like jquery dialog jqueryui.com/demos/dialog. That won't be blocked, and it's going to be faster.
  • Suneth Kalhara
    Suneth Kalhara about 12 years
    :) this is for add a background music for website, the site must be full reload within pages and music need continuously playing without one second gap. this is my problem. i can't use ajax or iframes :( . have any solution for this
  • Suneth Kalhara
    Suneth Kalhara about 12 years
    :) this is for add a background music for website, the site must be full reload within pages and music need continuously playing without one second gap. this is my problem. i can't use ajax or iframes :( . have any solution for this
  • Suneth Kalhara
    Suneth Kalhara about 12 years
    no i try this before, user click on button popup blocker allow it. and i need this when the page load event automatically opens the popup and play the music. when i trigger this click function using jquery firefox blocks the popup :)
  • demee
    demee about 12 years
    Then i think there may be no solution for your problem. But there would be workaround, see what jamendo does jamendo.com. They have player on page, and page itself sits in (i'm guessing) iframe on top of it. You can keep browsing site, and still listing to music. They had an option to detach player from window some time ago, but it look like they got rid of it (maybe because of the same issue you're having).
  • demee
    demee about 12 years
    (sorry I know you said you can't use iframes, but it looks like the only option)
  • Aaron Gibralter
    Aaron Gibralter over 11 years
    Isn't playing music when you navigate to a website a big no-no in web design? It's supremely annoying to the user, especially if he or she unsuspectingly visits a webpage at work without headphones on...
  • sehe
    sehe over 10 years
    @thecoshman this edit objectively adds (a little) value. I'd say, just welcome the help!
  • thecoshman
    thecoshman over 10 years
    @sehe it's such a tiny slither of potential value though, and the sheer number of edits your man makes! I did mean my comment more tongue in cheek though. Obviously no harm done, but my lord!
  • sehe
    sehe over 10 years
    Wokay. It was not at all obvious (to me) that you meant that in a "no-harm-done" fashion, though. I'm glad you're just amused. Yes, Peter has an impressive track record of editing :/
  • user280109
    user280109 over 9 years
    @demee your example is great. I am trying to do something similar, but im trying to open a new window if the user clicks the "ok" button on a "confirm" dialog. Firefox doesn't seem to be smart enough to realise the open window is being called by a user action, though i guess the coder could put something misleading in the confirmation box, maybe that is why firefox won't allow it, then again the coder could put something misleading on the button in your example... heres a bare bones demo of what i am trying to achieve: jsfiddle.net/6me4k18d/5 but it doesnt work
  • bombek
    bombek almost 4 years
    I found this issue when I created a tampermonkey script for myself use only. Your answer "Don't open pop up advertising. It's annoying." is actually not an answer but a comment.