New Revised CSS Library Forums Web Tools
FAQs Awards Usage Terms Contact
Categories
Other Sections
Sweet Ads
Compatibility
Bookmark online:


FF1+ IE5+ Opr7+

Open select links in new window

Author: Dynamic Drive

Description: This one of a kind script makes it easy to specify certain links on your page open in a new window, and with greater control than HTML's "target" attribute. You can designate arbitrary links- or even entire groups of links- open in a new window by doing one of the following:

1) Give the link a class="nwindow" attribute.
2) Or, to get an entire group of links to open in a new window, wrap them all inside a container with class="nwindowcontainer", such as <div class="nwindowcontainer">links here</div>.

And to make it all worthwhile, this script supports two modes of operation- automatic or manual. In the former, the designated links (by doing one of the above steps) will automatically open in a new window. In "manual" mode however, visitors use a checkbox to toggle between the designated links opening in a new window or current instead. Control and versatility is what this script is all about!

Demo: (mode 2 "manual" shown)

Open designated* links in new window

Last two links below given class="nwindow" Links below wrapped in <td class="nwindowcontainer">

Directions: Developer's View

Simply add the following script to the <BODY> section of your page, at the very end following all links on the page:

Select All

Usage notes

As noted, the script lets you designate links to open in a new window using two ways:

1) Give the link a special class:

<a href="http://www.dynamicdrive.com" class="nwindow">Dynamic Drive</a>

2) Wrap groups of links in a container with a special class:

<div class="nwindowcontainer">
link 1
link 2
etc
</div>

Furthermore, you have the option of letting the visitor decide whether these links should open in a new window, by adding a checkbox to your page:

<form name="targetmain"><input type="checkbox" name="targetnew" checked
onClick="applywindow(targetlinks)">Open designated links in new window</form>

The mere presence of this checkbox will cause the script to switch to "manual" mode.