Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-18-2009, 05:49 PM   PM User | #1
weaksauce
New Coder

 
Join Date: Nov 2007
Posts: 34
Thanks: 9
Thanked 0 Times in 0 Posts
weaksauce is an unknown quantity at this point
Leaving Site Function

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:
Code:
<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):
Code:
<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>
__________________
Time after Time
weaksauce is offline   Reply With Quote
Old 03-18-2009, 05:55 PM   PM User | #2
TinyScript
Regular Coder

 
Join Date: Mar 2009
Location: Portland Oregon
Posts: 690
Thanks: 44
Thanked 63 Times in 62 Posts
TinyScript is on a distinguished road
I think you could just do it with onunload or something
http://www.w3schools.com/jsref/jsref_onunload.asp
TinyScript is offline   Reply With Quote
Old 03-18-2009, 06:01 PM   PM User | #3
weaksauce
New Coder

 
Join Date: Nov 2007
Posts: 34
Thanks: 9
Thanked 0 Times in 0 Posts
weaksauce is an unknown quantity at this point
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.
__________________
Time after Time
weaksauce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:38 AM.


Advertisement
Log in to turn off these ads.