Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-23-2013, 03:55 AM   PM User | #1
madhulika
New to the CF scene

 
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
madhulika is an unknown quantity at this point
Thumbs up warn User Whenever They Leave the browser in javascript??

window.onbeforeunload = confirmExit;
function confirmExit() {
return "Please login or signup to save your images";
}

whenever i click on any link on website it shows dis message,

i only wants to show message when user close the browser!!!

plz suggets
madhulika is offline   Reply With Quote
Old 01-23-2013, 06:06 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,528
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
JavaScript only knows if the page is about to be unloaded - it doesn't know why the page is being unloaded. It therefore can't distinguish between reloading the current page, going to another page on the same site, going to a page on a different site, or closing the current tab, or closing the browser.

You might be able to set something from a click event on links in the page that you can test for from the beforeunload code to detect if the reason for the unload is that they clicked a link - that would get rid of some of the unloads not related to closing the browser.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 01-23-2013, 07:54 AM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,549
Thanks: 9
Thanked 479 Times in 462 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
onbeforeunload will stop "popping up" in firefox and chrome soon, don't use it anymore.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5% IE10:8.5%
rnd me is offline   Reply With Quote
Old 01-23-2013, 02:36 PM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
Quote:
Originally Posted by rnd me View Post
onbeforeunload will stop "popping up" in firefox and chrome soon, don't use it anymore.
oh, crud. is there something else we can use?
xelawho is offline   Reply With Quote
Old 01-23-2013, 03:16 PM   PM User | #5
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
... in the meantime you could use a simple flag...

Code:
window.onbeforeunload = confirmExit;
var waslink = false;

function confirmExit() {
    if (!waslink) {
        return "Please login or signup to save your images";
    }
    waslink = false;
}

var lnks = document.getElementsByTagName("a");

for (var i = 0; i < lnks.length; i++) {
    lnks[i].onmousedown = function () {
        waslink = true;
    }
}
xelawho is offline   Reply With Quote
Reply

Bookmarks

Tags
browser close

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:13 AM.


Advertisement
Log in to turn off these ads.