...

View Full Version : Leaving Site Function



weaksauce
03-18-2009, 06: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>

TinyScript
03-18-2009, 06:55 PM
I think you could just do it with onunload or something
http://www.w3schools.com/jsref/jsref_onunload.asp

weaksauce
03-18-2009, 07:01 PM
The problem with onunload is that it triggers the event with every link and during refreshes. I would only need this prompt if the user was going to a specific outside link where we do not monitor the site because we have multiple DNS's.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum