[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • Last Modified:

Leaving Website Alert Box

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
CVNetworks
Asked:
CVNetworks
1 Solution
 
leakim971PluritechnicianCommented:
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
 
Gurvinder Pal SinghCommented:
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
 
Gurvinder Pal SinghCommented:
ohh...k

I was thinking if you are asking to show that prompt when user clicks on browser's close button... My bad
0
 
Nicholas FordCommented:
Take a look at this script, I think it will do what you want.
0
 
CVNetworksAuthor Commented:
This is exactly what I was looking for.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now