The Shifted Librarian - Shifting Libraries at the speed of byte

How to Add a Script to Open Links in a New Window

Written for Radio 8 using the Transmitter template, although you should be able to adapt it to other templates as well. You should also be able to add almost any Javascript code using this same process. Send me your comments and suggestions for improving it!

In order to provide an option for visitors to choose to open links in new windows, I added some Javascript code I stole from RandomWalks. To  do this, go to your Prefs in Radio and then select your Home Page Template. Copy the following code, and paste it somewhere in between the <head> and </head> tags in the template.

<script language="JavaScript"><!--
// thanks to for this code
function targetLinks(boNew) {
if (boNew)
where = "_blank";
where = "_self";
for (var i=0; i<=(document.links.length-1); i++) {
document.links[i].target = where;
// -->

Here's where I put it in my template.

image of code

Then scroll down further, past the <body> tag but before the </body> tag, and find where you want to put the box and text that will be visible to the user. Copy the following text, and paste it in to your template.

<form name="targeter">
<input type="checkbox" name="targetbox" id="tcheck"
<label for="tcheck" style="cursor: hand;">
    links open windows

This is what it will look like on your page:

This is where I put it in my template.

image of code

To change the text next to the box, simply change the text "links open windows" in the above code to whatever you want it to say. Then just submit your changes, and you're done. Wait a few seconds for the changes to upstream, and then go to your home page and test it out!

Did I miss something? Let me know.