creating a link on webpage

C

crazyjxx

I have been trying to create my own webpage and I am wondering if there
is a way to create a link on my webpage that sends the person to
multiple urls in new windows. For example if they click on a link on
my page "Cnn and Yahoo" it will open two seperate pages in new windows
Cnn.com and yahoo.com. I have been using a html edditor to create my
page so the html code to be able to do this would be greatly
appreciated.

Thanks alot
 
J

Jonathan N. Little

I have been trying to create my own webpage and I am wondering if there
is a way to create a link on my webpage that sends the person to
multiple urls in new windows. For example if they click on a link on
my page "Cnn and Yahoo" it will open two seperate pages in new windows
Cnn.com and yahoo.com. I have been using a html edditor to create my
page so the html code to be able to do this would be greatly
appreciated.

Thanks alot

Not with HTML. Would require a script AND would probably piss-off your
visitors so you will not have to worry about them coming back! If you
want to open up two URLs create to links.

<a href="CnnURL">Go to Cnn</a> <a href="YahooURL">Go to Yahoo</a>

Analogy: When you turn the knob on your house's front door you expect it
to just open the front door and not simultaneousness open the back door,
cellar door, garage... right?
 
J

jojo

I have been trying to create my own webpage and I am wondering if there
is a way to create a link on my webpage that sends the person to
multiple urls in new windows. For example if they click on a link on
my page "Cnn and Yahoo" it will open two seperate pages in new windows
Cnn.com and yahoo.com. I have been using a html edditor to create my
page so the html code to be able to do this would be greatly
appreciated.

Thanks alot

Yes, it is possible, but it is not with pure HTML. You need to use
JavaScript here. The problem is that many users do not have JS enabled
for security reasons, so /they/ might not be able to use those links. A
possibility might be to use two links and delete one with JS and modify
the other. That would ensure that users with JS switched off still view
all linked pages.
To realize that you have to put the following code into the <head> of
your page:

<script language="javascript" type="script/javascript">

document.getElementById("link2").style.display="none"
document.getElementById("link1").innerHTML="Yahoo and CNN"

function doubleLink(page){
win=window.open()
win.location.href=page
}

</script>


Your links have to look like this:

<a href="www.yahoo.com" target="_blank" id="link1"
onclick="doubleLink('www.cnn.com')">Yahoo</a>

<a href="www.cnn.com" target="_blank" id="link2">CNN</a>

HTH,
jojo
 
J

Jonathan N. Little

jojo said:
Yes, it is possible, but it is not with pure HTML. You need to use
JavaScript here. The problem is that many users do not have JS enabled
for security reasons, so /they/ might not be able to use those links. A
possibility might be to use two links and delete one with JS and modify
the other. That would ensure that users with JS switched off still view
all linked pages.
To realize that you have to put the following code into the <head> of
your page:

<script language="javascript" type="script/javascript">

document.getElementById("link2").style.display="none"
document.getElementById("link1").innerHTML="Yahoo and CNN"

function doubleLink(page){
win=window.open()
win.location.href=page
}

</script>


Your links have to look like this:

<a href="www.yahoo.com" target="_blank" id="link1"
onclick="doubleLink('www.cnn.com')">Yahoo</a>

<a href="www.cnn.com" target="_blank" id="link2">CNN</a>

HTH,

Nice idea (where id JS is disabled you will see two links), but a couple
of problems.

1) You cannot format the style of the links until *after* they are
created in the document. Therefore you either have to call it in a
script element inline *after* where the links appear in the BODY or you
have to make an initialization function that is called on the document's
onload event.

2) the href's in links must have the protocol 'http://' else they will
look for the URLs locally.
 
J

jojo

Nice idea (where id JS is disabled you will see two links), but a couple
of problems.

1) You cannot format the style of the links until *after* they are
created in the document. Therefore you either have to call it in a
script element inline *after* where the links appear in the BODY or you
have to make an initialization function that is called on the document's
onload event.

Oh, you're right... I always forget this... Place the <script> /foo/
2) the href's in links must have the protocol 'http://' else they will
look for the URLs locally.

You're right again. Didn't recognize that I missed it.
 
D

Dan

jojo said:
You're right again. Didn't recognize that I missed it.

And end the "onclick" attribute with ";return false" to make sure that
if the Javascript is executed, the regular link isn't also followed.
 
J

jojo

Dan said:
And end the "onclick" attribute with ";return false" to make sure that
if the Javascript is executed, the regular link isn't also followed.
ASFAIK the "onclick" is executed anyway, so you don't need the "return
false". The advantage: the JS has to open only one link, the other one
is executed the "common" way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top