I'm trying to find an easy way to add a confirm dialog to all links that take the user away from our website without doing it manually for each link. The issue is that none or very few of the links have IDs. So how do i add onclick to links that don't have an id? Here's my code:
_______________
_brian.
Code:
function fixExitLinks(){
var myLinks = document.links;
for(var i=0;i < myLinks.length;i++) {
var thehref = myLinks[i].href.toString();
if(thehref.indexOf("mydomain.com") == -1){
myLinks[i].onclick = return confirmExit();
}
}
}
function confirmExit(){
if(confirm('You are leaving our site')){
return true;
} else {
return false;
}
}
Code:
<body onLoad="fixExitLinks();">
_______________
_brian.