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)
11 * JavaScript to open non-local links in a new window.
14 * in the <head>...</head> section of your page, add the following line:
16 * <script type="text/javascript" src="nucleus/javascript/opennew.js"></script>
18 * Then, add the following to your <body> tag:
20 * <body ... onload="setOpenNewWindow(true);">
22 * And you're all done.
24 * Variables that can be overridden if necessary:
25 * local = something to recognize local URLs (by default, if your page is something like
26 * http://www.example.com/path/page.html, then local will be automatically set to
27 * http://www.example.com/path/)
28 * exception = something to recognize exceptions to the local check. You might need this
29 * when you use a 'click-through' type of script (e.g. when
30 * http://www.example.com/path/click.php?http://otherpage.com/ would
31 * auto-redirect to otherpage.com and record a click in your logs)
32 * In most of the cases, this variable is unneeded and can be left empty
33 * destinationFrame = name of the destination frame (by default this is "_blank" to spawn a
34 * new window for each link clicked)
38 var local = document.URL.substring(0,document.URL.lastIndexOf('/'));
40 var destinationFrame = "_blank";
42 function setOpenNewWindow(newWin) {
44 from = ""; to = destinationFrame;
46 from = destinationFrame; to = "";
49 for (var i=0; i<=(document.links.length-1); i++) {
50 if (document.links[i].target == from) {
52 var href = document.links[i].href;
53 var isLocal = (href.indexOf(local) != -1);
54 if (isLocal && ((exception=="") || (href.indexOf(exception) != -1)))
57 document.links[i].target = to;