|
|
|
03/10/2005 - 21:25 (Category: Javascript) Thanks to the following method, visitors can choose where links will be opened (in a new browser window or in the same browser window). The script consists of two parts: the first one within <head> and </head> tags, and the other one within <body> and </body> tags. This script is compatible with Internet Explorer, Netscape 6, Mozilla, Safari, Opera. Part one (within <head> and </head> tags):
<script language="JavaScript" type="text/JavaScript">
<!--
var mioSito="http://www.wowarea.com";
function wo(_checked)
{
where = _checked?"_blank":"_self";
for (var i=0; i<=(document.links.length-1); i++)
{
if(document.links[i].href.indexOf(mioSito)<0)
document.links[i].target=where;
}
}
// -->
</script>
Part two (within <body> and </body> tags): <form name="form"> <input type="checkbox" name="checktarget" onclick="wo(this.checked)"> Open links in a new window. </form> (Notice that you must place the second code snippet shown above at the same location where you want links and checkboxes to be displayed) The mioSito variable contains your web site's domain name. The wo(_checked) function inspects all links in the page, analyzing the href tag. When the examined domain name and that stored into the mioSito variable match, the link will be opened in the same window. On the contrary, when an external link is reached (i.e.: domain names don't match because they aren't equal) then the checkbox is inspected. In this case the link will be opened in a new window or in the same window, depending on the checkbox status (i.e.: checked status means 'new window' whereas not checked status means 'same window'). Go back
DISCLAIMER: |
|