SCR24: Using script to open a new window on user request

Applicability

Description

The objective of this technique is to avoid confusion that may be caused by
the appearance of new windows that were not requested by the user. Suddenly
opening new windows can disorient or be missed completely by some users.
If the document type does not allow the target attribute (it
does not exist in HTML 4.01 Strict or XHTML 1.0 Strict) or if the developer
prefers not to use it, new windows can be opened with ECMAScript. The
example below demonstrates how to open new windows with script: it adds an
event handler to a link (a element) and warns the user that the
content will open in a new window.

Examples

Example 1:

Markup:

The script is included in the head of the document, and the link has
an id that can be used as a hook by the script.