...

View Full Version : javascript external link



danielandlisa
12-03-2009, 02:55 PM
Hi, is it possible to make a external javascript link by giving all the external
links a class name then use getelementbytagname in the js file with
a function to alert the hes leaving the website and let him choose if
he wants to stay or leave.
well thats what im trying to do but i dont know how to write the
function for it maybe i could get a suggestion or a link to agood tutorial.

/ thanks lisa

abduraooft
12-03-2009, 03:34 PM
You may set a class attribute on those anchors and use getElementsByClassName() (http://codingforums.com/showthread.php?t=154727) method to fetch all such links. Then you may add an event-listener for them for the click event, see http://www.quirksmode.org/js/events_advanced.html

danielandlisa
12-03-2009, 03:38 PM
Ok thanks but i really got to see a example how its done im to much of a beginner to write the js function myself.
check your mail soon by the way i sent you a mail.

glenngv
12-04-2009, 01:23 AM
<a href="http://www.google.com" class="external_link">Google</a>
<a href="http://www.yahoo.com" class="external_link">Yahoo</a>
...and so on...
<script type="text/javascript">
function setPromptOnExternalLinks(){
var links = document.links;
for (var i=0; i<links.length;i++){
if (links[i].className.indexOf("external_link") != -1){
links[i].onclick = function(){
return prompt("You are about to go to an external website, do you want to continue?");
}
}
}
}

setPromptOnExternalLinks(); //you may call this function onload if you want
</script>

Philip M
12-04-2009, 09:12 AM
[CODE return prompt("You are about to go to an external website, do you want to continue?");
[/CODE]

Surely should be:-

return confirm("You are about to go to an external website, do you want to continue?");

I am tempted to respond to the prompt box by typing in something like
"Yes, of course I want to continue, you nerd. Otherwise I would not have clicked on the external link." :D:D

glenngv
12-04-2009, 10:00 PM
Surely should be:-

return confirm("You are about to go to an external website, do you want to continue?");

I am tempted to respond to the prompt box by typing in something like
"Yes, of course I want to continue, you nerd. Otherwise I would not have clicked on the external link." :D:D
confirm is the right one. I didn't know why I used prompt :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum