weaksauce
03-18-2009, 05:49 PM
I'm trying to build something with either javascript or php that will prompt a security message when leaving the site.
I did some research and I found very basic ways to this but it only applied to one link. I would like to simply add a onclick to any link on any page that will tag the link as an exiting link.
Here the basic code, this is the first default page:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Link Test</title>
<script type="text/javascript">
<!--
function Terms() {
popup=window.open('security.php','windowName','width=500,height=300');
if (!popup.opener) popup.opener = self;
}
-->
</script>
</head>
<body>
<a href="#" onClick="Terms()">www.google.com</a>
</body>
</html>
And then here's the second page (security.php):
<html>
<head>
<script type="text/javascript">
<!--
function confirmation() {
var answer = confirm("Are you sure you want to leave?")
if (answer){
window.location = "http://www.google.com/";
//This location above needs to be dynamic to the link from the first page
}
else{
window.close();
}
}
//-->
</script>
</head>
<body>
<form>
<input type="button" onclick="confirmation()" value="Leave?">
</form>
</body>
</html>
I did some research and I found very basic ways to this but it only applied to one link. I would like to simply add a onclick to any link on any page that will tag the link as an exiting link.
Here the basic code, this is the first default page:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Link Test</title>
<script type="text/javascript">
<!--
function Terms() {
popup=window.open('security.php','windowName','width=500,height=300');
if (!popup.opener) popup.opener = self;
}
-->
</script>
</head>
<body>
<a href="#" onClick="Terms()">www.google.com</a>
</body>
</html>
And then here's the second page (security.php):
<html>
<head>
<script type="text/javascript">
<!--
function confirmation() {
var answer = confirm("Are you sure you want to leave?")
if (answer){
window.location = "http://www.google.com/";
//This location above needs to be dynamic to the link from the first page
}
else{
window.close();
}
}
//-->
</script>
</head>
<body>
<form>
<input type="button" onclick="confirmation()" value="Leave?">
</form>
</body>
</html>