»
EnglishFrenchVietnamese

Print - Offsite Links - JavaScriptBank.com

Full version: jsB@nk » Link » Offsite Links
URL: https://www.javascriptbank.com/offsite-links.html

Offsite Links © JavaScriptBank.comUsing this JavaScript, any links on a Web page to another domain will open in a new window.

Full version: jsB@nk » Link » Offsite Links
URL: https://www.javascriptbank.com/offsite-links.html



JavaScript
<script language="javascript">// Created by: William Bontrager :: http://willmaster.com/possibilities/var thispagedomain = ExtractDomainName(document.URL);for(var i = 0; i <= document.links.length - 1; i++) {  var url = document.links[i].href.toLowerCase();  if(url.indexOf('http://') != 0) { continue; }  var hrefdomain = ExtractDomainName(url);  if(thispagedomain != hrefdomain) {     document.links[i].target = '_blank';  }}function ExtractDomainName(s) {  var i = s.indexOf('//');  if(i > -1) { s = s.substr(i+2); }  i = s.indexOf('/');  if(i > -1) { s = s.substr(0,i); }  i = s.indexOf(':');  if(i > -1) { s = s.substr(0,i); }  var re = /[a-z]/i;  if(! re.test(s)) { return s; }  var a = s.split('.');  if(a.length < 2) { return s; }  var domain = a[a.length-2] + '.' + a[a.length-1];  if(a.length > 2) {    if(a[a.length-2].length==2 && a[a.length-1].length==2) {      domain = a[a.length-3] + '.' + domain;      }    }  return domain.toLowerCase();}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<a href="http://JavaScriptBank.com">JavaScriptBank.com</a><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->