8

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Suneth Kalhara
  • 1,116
  • 4
  • 16
  • 40
  • FF blocks popups even if the popup blocker is completely turned off. Use `about:config` and search for `popup` to see why. I am not completely sure, yet, what this settings really do and how to enable unlimited popups for certain applications which need them. – Tino Dec 18 '12 at 21:11

2 Answers2

11

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/

demee
  • 582
  • 5
  • 18
  • 3
    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 http://jqueryui.com/demos/dialog/. That won't be blocked, and it's going to be faster. – demee May 06 '12 at 15:18
  • 1
    :) 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 May 06 '12 at 15:25
  • 1
    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 :) – Suneth Kalhara May 06 '12 at 15:38
  • Then i think there may be no solution for your problem. But there would be workaround, see what jamendo does http://www.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 May 06 '12 at 15:43
  • (sorry I know you said you can't use iframes, but it looks like the only option) – demee May 06 '12 at 15:51
  • 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... – Aaron Gibralter Sep 27 '12 at 17:06
  • @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: http://jsfiddle.net/6me4k18d/5/ but it doesnt work – user280109 Oct 31 '14 at 15:57
3

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ali
  • 261,656
  • 265
  • 575
  • 769
  • :) 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 May 06 '12 at 15:25
  • @thecoshman this edit objectively adds (a little) value. I'd say, just welcome the help! – sehe Oct 10 '13 at 10:19
  • @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! – thecoshman Oct 10 '13 at 10:23
  • 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 :/ – sehe Oct 10 '13 at 10:24
  • 1
    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. – bombek Aug 02 '20 at 13:15