Popup Window Controls

Mozilla and Firefox allow users to control most unsolicited attempts to open new windows such as popup and popunder windows. Learn how to detect Popup Controls, how to ask your readers to enable popups for your site and how to get the benefits of popup windows without using popup windows.

Using the Preference for Privacy & Security > Popup Windows, users can:

  • allow all sites to open Popup windows except for sites which the user has explicity denied permission

What Popup Windows are suppressed?

Mozilla will attempt to suppress all calls to window.open() which occur in the following circumstances:

  • global script which is executed as the document is loading
  • script executed as part of a onload event handler
  • script executed in setTimeout() or setInterval()

What Popup Windows are not suppressed?

Any attempt to open a popup window that is the direct result of user action, such as clicking on a hyperlink, should succeed in opening popup windows even if the user has popup controls enabled on your site.

Detecting Suppressed Popups Windows

If a user has popup controls enabled for your site, any attempt to call window.open in global script, in an onload handler or in setTimeout() or setInterval() will return null rather than a reference to the opened window.

<html>
 <head>
  <title>Detecting Popup Controls</title>
  <script type="text/javascript">
    <!--
    // attempt to open an unsolicited window
    var popup = window.open('about:blank', 'popup');
    if (!popup)
     {
      // the user has suppressed the popup
     }
    // -->
  </script>
 </head>
 <body>
   <!-- your page here -->
 </body>
</html>

If your popup window is crucial to the operation of your web site you can notify the user and ask them to add your site to the list of sites which are allowed to use unsolicited popup windows. You can also provide a hyperlink which can be used to open a popup window even in the event that the user has suppressed unsolicited popups on your site.

Replacements for Popup Windows

If your popup was created during the time the web page was loading, you may consider using document.write() to emit appropriate HTML which will contain the same information as the popup window. You can also use either the advanced features in the Document Object Model (DOM) or innerHTML to create the appropriate HTML.

Example

The example tag links to devedge-temp.mozilla.org This example illustrates detecting suppressed popup windows as well as an approach for replacing popup windows with inline HTML using innerHTML.

Original Document Information

  • Author(s): Bob Clary
  • Last Updated Date: December 5th, 2002
  • Copyright © 2001-2003 Netscape.