freakish
freakish

Reputation: 56467

Popup block under FireFox

When I use JavaScript function

var w = window.open('about:blank');

under FireFox the popup is blocked and I get the option to unblock it. Even if I do this the popup does not appear (I believe the JavaScript needs to be fired one more time).

But I need to be sure that the popup fires even when the code runs for the first time.

So what I want is to check whether FireFox allows popups. There are two possibilities:

  1. This should be done in such a way that if it does not allow then show appropriate message and wait (setTimeout?) until the access is granted (and open popup afterwards).

  2. Before doing this window.open operation check if FireFox allows popups. If it does not, then show appropriate message (and do not allow the user to go deeper inside app without granting access) but if it does allow then do not open the popup (user does not need to see that he can fire popups). All of this can be done for example when user logs in (all of main popups require the user to be loged in).

So that's the idea. But what about JavaScript? How can I achieve this? Is it even possible?

Upvotes: 0

Views: 3400

Answers (1)

Dr.Molle
Dr.Molle

Reputation: 117324

When firefox blocks a popup, the reference to w will be null.

So my suggestion:

  • Try to open the popup
  • check if w is null
  • when w is null, show the message
  • put an element into the message with a notice like "click here to open the window"
  • observe the click-event of this element, when it fires, open the popup(firefox usually will not block a popup forced by a click-event) and hide the message
  • otherwise: hide the message after xxx seconds

Other ideas:

  • observe the click-event of the document and open the popup then when it's open yet(and remove the click-observation)
  • when the popup is null, use a modal-dialog that blocks the UI and give the user the option to open the popup via a click inside the dialog. I would prefer this, because here you have the chance to determine if the user want's to allow the popup.
  • don't use popups at all, when possible use inline-popups, e.g. a jquery-dialog, LightBoxes, etc.

Upvotes: 1

Related Questions