Forum Moderators: open

Message Too Old, No Replies

Open Link in New Window if Domain Name is Different

How to

         

eSite

3:46 pm on Sep 18, 2004 (gmt 0)



Hi,

How could I very simply make a page open in a new window if the domain name in the href attribute is different from a certain value?
I would like this to be applied to all the links in the current page.

Big thanks in advance.

adni18

8:47 pm on Sep 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm just guessing what you might mean, and here's my solution:

<base target="_blank">
<a href="http://www.cognitivedistortion.com">Cognitive Distortion (New Window)</a><br>
<a href="http://www.digitalblasphemy.com">DigitalBlasphemy (New Window)</a><br>
<a href="http://www.ianadesign.com">Ian A. Design</a>

[edited by: adni18 at 8:53 pm (utc) on Sep. 18, 2004]

adni18

8:49 pm on Sep 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is another way:

<head>
<script language=javascript>
<!--
var trip=-1;
function changeTarget() {
trip++;
var linknum=eval(document.body.getElementsByTagName("a").length);
document.body.getElementsByTagName("a")[trip].target='_blank';
if(trip<eval(linknum)-eval(1)){window.setTimeout("changeTarget()",0001)}
}
//-->
</script>
</head>
<BODY onLoad=changeTarget()>
<base target="_blank">
<a href="http://www.google.com">Google (New Window)</a>
<a href="http://www.dogpile.com">Dogpile (New Window)</a>
</BODY>

[edited by: adni18 at 9:15 pm (utc) on Sep. 18, 2004]

adni18

8:52 pm on Sep 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Waiting...

eSite

9:50 pm on Sep 18, 2004 (gmt 0)



Well I don't understand what your script is supposed to do (nor how) but I tested it and it opens every links in a new window.

Here are some precisions :
- It must be valid XHTML Strict 1.0
- It must be global (all links in the page)
- No code must be added to links or group of links (plug&play)

adni18

10:15 pm on Sep 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



well if you wanted an xml script then don't post it in Javascript! And I still wasn't sure what you meant. It sounded as though you wanted it to open in a new window. I stink at xml BTW.

eSite

10:36 pm on Sep 18, 2004 (gmt 0)



Well hyperlinks are in XHTML and the code that make them open in a new window is a JavaScript.