Forum Moderators: phranque
Something like this but this will not work...
<a href="http://www.thiswebpage.com" javascript:confirm('Do you want to continue to this webpage?');">This Webpage</a>
Thank you.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
<head>
<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function gosomewhere(){
var yes = confirm("Would you like to go to this webpage?");
location.replace("http://www.msn.com");
}
//-->
</SCRIPT>
</head>
<body>
<a href="#" onclick="javascript:gosomewhere();">Click Me</a>
</body>
</html>
You can do it all inline like:
<a href="http://www.thiswebpage.com" onclick="if (confirm('Do you want to continue to this webpage?')) { window.location.href = this.href } return false;">This Webpage</a>
But it would be alot cleaner (and much easier if you have more than one link you want to use the effect on) to use a function, like...
<script type="text/javascript">
<!--
function navConfirm(loc) {
if (confirm('Do you want to continue to this webpage?')) {
window.location.href = loc;
}
return false; // cancel the click event always
}
//-->
</script>
Then make your links like:
<a href="http://www.thiswebpage.com" onclick="return navConfirm(this.href);">This Webpage</a>
Jordan