?
Solved

Leaving Website Alert Box

Posted on 2011-02-10
5
Medium Priority
?
631 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 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:Gurvinder Pal Singh
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:Gurvinder Pal Singh
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:Nicholas Ford
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Suggested Courses

800 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