Open HyperLinks in a Second Window - Neils Resource WebOpen HyperLinks in a Second Window - Neils Resource WebNew Window Links - Javascript - Web Dev. - Neils Resource Web

Contract Menu | Expand Menu

Summary of Content

This javascript allows the viewer to open any 'off site' links in a new window (so viewers will come back to your page afterward. The default is set to not open links in a new window, but by checking the box the link will open in a new window - try it on this link to Dynamic Drive.

(P.S If you see a grey border around the page, its an IE only script, details at the foot of the page)

Open any links selected in a new window

Code for Opening Hyperlinks in a New Window
Head Section
<SCRIPT type="text/javascript">

* Open links in new window Script- By spk100 (
* Script featured on/available at Dynamic Drive-
* Modified by DD. This notice must stay intact for use

//Enter "_blank" for new window (each time), "window2" for a set secondary window
var newwindow="_blank"

function hyperlinks(target){
if (target) where = newwindow;
else where = "_self";
for (var i=0; i<=(document.links.length-1); i++){
var linkobj=document.links[i].href
if ( linkobj.indexOf("javascript:") ==-1 && linkobj.indexOf("#") ==-1){
if (target && where!="_blank") // added routine- open window in set secondary window
if (window.window2 && !window2.closed)
return false
if (newwindow=="window2") document.links[i].onclick = "";
document.links[i].target = where;

function inithyperlinks(){ // added routine
if (document.targetform.targetnew.checked)


// -->

A small I. E. only script puts a border around your page (place at top of body section)
<script language="JavaScript">
if (document.all){
with ({
borderWidth=5; borderStyle='solid'; borderColor='#C0C0C0';

Hyperlink titles may have been abbreviated, (right click on the link and select properties for the full URL)

Top of the PageTop of the PageA double mouse click anywhere on the page will take you back to the top (except when over hyperlinks)

Last Update: 17/01/2008 - Open Hyperlinks in a Second Window - Neils Resource Web

html 4.01 strict css 2.1 javascript 1.2