この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください！
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.
Popup Window Controls Configuration
Using the Preference for <tt>Privacy & Security > Popup Windows</tt>, 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 <tt>window.open()</tt> 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 <tt>setTimeout()</tt> or <tt>setInterval()</tt>
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 <tt>window.open</tt> in global script, in an <tt>onload</tt> handler or in <tt>setTimeout()</tt> or <tt>setInterval()</tt> will return null rather than a reference to the opened window.
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 <tt>document.write()</tt> 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 <tt>innerHTML</tt> to create the appropriate HTML.
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 <tt>innerHTML</tt>.
Original Document Information
- Author(s): Bob Clary
- Last Updated Date: December 5th, 2002
- Copyright © 2001-2003 Netscape.