»
EnglishFrenchVietnamese

Print - Open Links Option II - JavaScriptBank.com

Full version: jsB@nk » Link » Open Links Option II
URL: https://www.javascriptbank.com/open-links-option-ii.html

Open Links Option II © JavaScriptBank.comGive and display the radio option to open links in either a new window or in the same window. Simple to set-up and completely unobtrusive.

Full version: jsB@nk » Link » Open Links Option II
URL: https://www.javascriptbank.com/open-links-option-ii.html



JavaScript
<script type="text/javascript" name="openLinks.js">// Created by: Sandeep Gangadharan / Lee Underwood :: http://www.sivamdesign.com/home/// Original: Sandeep Gangadharan// Modified: Lee Underwood// getElementsByTagName Portion: Jeremy Keithfunction openLink() {  if (!document.getElementsByTagName) return false;  var links=document.getElementsByTagName("a");  for (var i=0; i < links.length; i++) {    if (links[i].className.match("newLink")) {      links[i].onclick=function() {        for (var i=0; i<=(document.links.length-1); i++) {          if (document.form1.tick.checked == true) {            document.links[i].target = window.open            window.location.href=window.location.href          }          if (document.form1.tick.checked == false) {            document.links[i].target != window.open            window.location.href=window.location.href          }        }      }    }  }}window.onload=openLink;</script>


HTML
<form name="form1">  <small><label for="1">Open link marked with <span style="color: red;">*</span> below in new window <input id="1" type="checkbox" name="tick"></label></small></form><br><!-- Add 'class="newLink"' (w/o single quotes) to those links you want to give the user the option to open in a new window.   --> <a href="http://javascript.com/" class="newLink">JavaScript.com</a> <span style="color: red;">*</span><br> <a href="http://javascriptbank.com/">JavaScriptBank</a><br> <a href="http://www.javascriptbank.com/forum/" class="newLink">JavaScript Forums</a> <span style="color: red;">*</span>