Solved

Leaving Website Alert Box

Posted on 2011-02-10
5
623 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

708 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

14 Experts available now in Live!

Get 1:1 Help Now