April 16, 2000 - Special Windows Targeting | WebReference

April 16, 2000 - Special Windows Targeting

Yehuda Shiran April 16, 2000
Special Windows Targeting
Tips: April 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

The following table specify the special target window names supported by JavaScript:

TargetDescription
_blankLoads the linked document into a new blank window. This window is not named.
_parentLoads the linked document into the immediate parent of the document the link is in.
_searchLoads the linked document into the browser's search pane. Available in Internet Explorer 5 or later.
_selfLoads the linked document into the same window the link was clicked in (the active window).
_topLoads the linked document into the topmost window.

When you specify the target "_blank", a new window pops up. For example, if you want a link to load in a new window, use the following code:

<A HREF="newpage.html" TARGET="_blank">A New Page</A>

The new window isn't named. In other words, it cannot be referenced by TARGET attributes of other elements. But what happens when we use a standard target name? Take a look at the next definition:

<A HREF="newtip.html" TARGET="tip">A New Tip</A>

In this case, we are providing a specific name for the new window. The new window is named "tip", so any other link or form that specifies TARGET="tip" causes the page to load in the same window. If there is no frame or window that matches the specified target, a new window is opened for the link. Take a look at the following example:

<A HREF="http://www.docjs.com/" TARGET="_blank">Home</A>
<A HREF="http://www.docjs.com/tips/" TARGET="_blank">Recent Tips</A>

Go ahead and fool around with these links:

Home
Recent Tips

Click the first link to launch our front page in a new window. Now click the second link to view our latest JavaScript tips in a new window. If you click that link again, yet another window is launched. As you can see, a new window is opened for each click. Let's experiment with the following links:

<A HREF="http://www.docjs.com/" TARGET="main">Home</A>
<A HREF="http://www.docjs.com/tips/" TARGET="main">Recent Tips</A>

Here they are:

Home
Recent Tips

Click the first link to launch our front page in a new window. Now click the second link to view our latest JavaScript tips in the same window (the one that was just opened). The new window is named "main", so any link or form that specifies TARGET="main" loads in the same window.

Learn more about windows creation and usage in Tutorial 1, Working with Windows.