2 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
3 * Copyright (C) 2002-2012 The Nucleus Group
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * (see nucleus/documentation/index.html#license for more info)
12 * $NucleusJP: opennew.js,v 1.4 2006/07/12 07:11:47 kimitake Exp $
14 * JavaScript to open non-local links in a new window.
17 * in the <head>...</head> section of your page, add the following line:
19 * <script type="text/javascript" src="nucleus/javascript/opennew.js"></script>
21 * Then, add the following to your <body> tag:
23 * <body ... onload="setOpenNewWindow(true);">
25 * And you're all done.
27 * Variables that can be overridden if necessary:
28 * local = something to recognize local URLs (by default, if your page is something like
29 * http://www.example.com/path/page.html, then local will be automatically set to
30 * http://www.example.com/path/)
31 * exception = something to recognize exceptions to the local check. You might need this
32 * when you use a 'click-through' type of script (e.g. when
33 * http://www.example.com/path/click.php?http://otherpage.com/ would
34 * auto-redirect to otherpage.com and record a click in your logs)
35 * In most of the cases, this variable is unneeded and can be left empty
36 * destinationFrame = name of the destination frame (by default this is "_blank" to spawn a
37 * new window for each link clicked)
41 var local = document.URL.substring(0,document.URL.lastIndexOf('/'));
43 var destinationFrame = "_blank";
45 function setOpenNewWindow(newWin) {
47 from = ""; to = destinationFrame;
49 from = destinationFrame; to = "";
52 for (var i=0; i<=(document.links.length-1); i++) {
53 if (document.links[i].target == from) {
55 var href = document.links[i].href;
56 var isLocal = (href.indexOf(local) != -1);
57 if (isLocal && ((exception=="") || (href.indexOf(exception) != -1)))
60 document.links[i].target = to;