Current location: Hot Scripts Forums » General Web Coding » JavaScript » Detect the browser window is being closed


Detect the browser window is being closed

Reply
  #1 (permalink)  
Old 11-19-11, 03:43 AM
faisals999 faisals999 is offline
Newbie Coder
 
Join Date: May 2011
Location: Sargodha, Pakistan
Posts: 27
Thanks: 4
Thanked 0 Times in 0 Posts
Detect the browser window is being closed

Hi all!

I need help right now
I want to show a pop up confirmation box whenever the user tries to close the browser window. I am trying this but this is not working

Code:
<script type="text/javascript" >
window.onunload = function() {
    confirmBox();
}

function confirmBox(){     
    var con = confirm("Do you want to delete session and cookies?");
    if(con == true)
        {logout();}
	else
	{
	window.location = "http://infoproductsincome.com";
	}
	
}
</script>
Reply With Quote
  #2 (permalink)  
Old 12-30-11, 07:39 AM
kshirin kshirin is offline
Newbie Coder
 
Join Date: May 2011
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
You can do this using JQuery with few lines of code. Use the code below:

jQuery(window).bind("beforeunload", function(){return confirm("Do you really want to close?") })
__________________
Free Webmaster Resources
Reply With Quote
Reply

Bookmarks

Tags
detect window closing, javascript window, windows unload


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to make my affiliate links open in a new window browser??? bigendz13 PHP 3 10-26-10 08:35 AM
Database in browser window deziner76hd Database 2 06-28-10 01:39 PM
show scrollbars in browser window alek3tt JavaScript 1 02-16-08 01:47 PM
How 2 Open a New Browser Window & Click a Submit Button Wildhalf JavaScript 3 12-08-06 03:34 PM
Browser Detect - will issue different coding joshlindem JavaScript 7 06-06-06 12:52 PM


All times are GMT -5. The time now is 02:08 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.