Solved

Leaving Website Alert Box

Posted on 2011-02-10
5
624 Views
Last Modified: 2012-05-11
On our corporate site we need to have links that are external to our company come up with an Alert Box stating they are leaving the site.  If they choose continue it will allow them to go to that link but if they cancel it will go back to the exisitng web page.  I am unsure of how to do this and want to see if anyone can help create a script that can accomplish this task.  
0
Comment
Question by:CVNetworks
5 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 34868232
Check this :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$("a").click(function(e) {
			var url = $(this).attr("href");
			if( url.toLowerCase().indexOf("http") == 0 ) {
				e.preventDefault();
				if( confirm("Do you really want to left our site?") ) {
					location.href = url;
				}
			}
		});
	});
</script>
</head>
<body>
<a href="http://www.google.com">Outside</a><br />
<a href="/page2.html">Inside</a>
</body>
</html>

Open in new window

0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34868233
javascript has onunload event for body, but using this you cannot return to the web-page since that event is called after the page is unloaded.

javascript also has onbeforeunload event, which is called before unloading happens, but it works only on IE.

So, i don't think there is any way to achieve your requirement
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34868241
ohh...k

I was thinking if you are asking to show that prompt when user clicks on browser's close button... My bad
0
 
LVL 2

Expert Comment

by:ndford005
ID: 34868245
Take a look at this script, I think it will do what you want.
0
 

Author Closing Comment

by:CVNetworks
ID: 34868263
This is exactly what I was looking for.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now