Comments on: Javascript “close hook” for browser window http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/ ruby, java and the rest Wed, 17 Jul 2013 11:30:54 +0000 hourly 1 http://wordpress.org/?v=3.4.2 By: Rahul http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-292618 Rahul Wed, 17 Jul 2013 11:30:54 +0000 http://amazing-development.com/?p=333#comment-292618 Thanks Vidya, its working Thanks Vidya,
its working

]]>
By: schlumpf http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-275923 schlumpf Sun, 21 Apr 2013 09:19:53 +0000 http://amazing-development.com/?p=333#comment-275923 Hi Vidya, thanks for your comment. It is not possible to distinguish between different browser close/reload events. Hi Vidya, thanks for your comment. It is not possible to distinguish between different browser close/reload events.

]]>
By: vidya http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-267909 vidya Tue, 26 Mar 2013 04:58:25 +0000 http://amazing-development.com/?p=333#comment-267909 hi confirmation code is working fine,but i need to display the confirmation dailogue only on closing the browser window but not on cliking the refresh button of the window ,can you plz tell me how to do this? Thanks in advance hi confirmation code is working fine,but i need to display the confirmation dailogue only on closing the browser window but not on cliking the refresh button of the window ,can you plz tell me how to do this?

Thanks in advance

]]>
By: Charles http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-228755 Charles Tue, 31 Jul 2012 17:55:46 +0000 http://amazing-development.com/?p=333#comment-228755 It helps a lot, thank you. I could use this routine to check if the user has left out something before closing the window. Really thank you! It helps a lot, thank you.

I could use this routine to check if the user has left out something before closing the window. Really thank you!

]]>
By: schlumpf http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-193210 schlumpf Mon, 05 Dec 2011 11:57:18 +0000 http://amazing-development.com/?p=333#comment-193210 Hi Bharani, the return value is sent to nowhere. Or if it is, I don't know. I'm not a javascript expert, just stumbled over this solution on the web and wrote it down here. Sorry, can't help you any further with that. Hi Bharani,
the return value is sent to nowhere. Or if it is, I don’t know. I’m not a javascript expert, just stumbled over this solution on the web and wrote it down here. Sorry, can’t help you any further with that.

]]>
By: bharani http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-192790 bharani Sat, 03 Dec 2011 10:39:07 +0000 http://amazing-development.com/?p=333#comment-192790 #Hi Bharani, #I don’t think you can find out the return value. Showing the popup message is the last thing that happens in the onbeforeunload event/method, and after that, #javascript is not running any more, so you can’t do anything in your script to react to the user’s input. I’m sorry. You could do a workaround by storing the #information that the user tried to close the window BEFORE showing the message, like this: ok but the return value is sent to where? i need that one so if we find means we can handle the allthings of browser is possible means we are done. [email protected] #Hi Bharani,

#I don’t think you can find out the return value. Showing the popup message is the last thing that happens in the onbeforeunload event/method, and after that, #javascript is not running any more, so you can’t do anything in your script to react to the user’s input. I’m sorry. You could do a workaround by storing the #information that the user tried to close the window BEFORE showing the message, like this:

ok but the return value is sent to where? i need that one so if we find means we can handle the allthings of browser is possible means we are done.
[email protected]

]]>
By: bharani http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-192789 bharani Sat, 03 Dec 2011 10:36:03 +0000 http://amazing-development.com/?p=333#comment-192789 Hi schlumpf , I was done task thanks for your help. And one more help if possible to handle the browser close,minimize etc in javascript or jquery if possible means i need how to handle entire browser options and properties,event Note: All browsers to handle Hi schlumpf ,

I was done task thanks for your help. And one more help if possible to handle the browser close,minimize etc in javascript or jquery if possible means i need how to handle entire browser options and properties,event

Note: All browsers to handle

]]>
By: schlumpf http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-192616 schlumpf Fri, 02 Dec 2011 20:04:47 +0000 http://amazing-development.com/?p=333#comment-192616 Hi Bharani, I don't think you can find out the return value. Showing the popup message is the last thing that happens in the onbeforeunload event/method, and after that, javascript is not running any more, so you can't do anything in your script to react to the user's input. I'm sorry. You could do a workaround by storing the information that the user tried to close the window BEFORE showing the message, like this: <code> <html><body> <script type="text/javascript"> triedToClose=false; window.onbeforeunload = function() { triedToClose = true return "Did you save your stuff?" } function checkClosing() { if (triedToClose) { alert("user tried to close the window but changed his mind") } else { alert("user didn't try to close the window") } } </script> <pre> To use: 1. click on the test link, see what happens. 2. try to close the window (browser (x)) - then select "stay on page" 3. click on the test link again - see that the message changed. <a href="#" onclick="checkClosing()" rel="nofollow">Some test link</a> </pre></body></html> </code> Please note that you can only evaluate the result if the user performs some action on your page, such as clicking on the test link. You would need to add the checkClosing() call to all your links and buttons and could even add it to the onbeforeunload function itself. not very elegant but the best I can do. Hope this helps! Hi Bharani,

I don’t think you can find out the return value. Showing the popup message is the last thing that happens in the onbeforeunload event/method, and after that, javascript is not running any more, so you can’t do anything in your script to react to the user’s input. I’m sorry. You could do a workaround by storing the information that the user tried to close the window BEFORE showing the message, like this:

<html><body>
<script type="text/javascript">
triedToClose=false;
window.onbeforeunload = function() {
triedToClose = true
return "Did you save your stuff?"
}

function checkClosing() {
if (triedToClose) {
alert("user tried to close the window but changed his mind")
} else {
alert("user didn't try to close the window")
}
}
</script>

<pre>
To use:

1. click on the test link, see what happens.
2. try to close the window (browser (x)) - then select "stay on page"
3. click on the test link again - see that the message changed.

<a href="#" onclick="checkClosing()" rel="nofollow">Some test link</a>
</pre></body></html>

Please note that you can only evaluate the result if the user performs some action on your page, such as clicking on the test link. You would need to add the checkClosing() call to all your links and buttons and could even add it to the onbeforeunload function itself. not very elegant but the best I can do.

Hope this helps!

]]>
By: Bharani http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-192554 Bharani Fri, 02 Dec 2011 14:10:42 +0000 http://amazing-development.com/?p=333#comment-192554 <!-- var confirmclose = true; var sucess = false; var ajaxSubmit = false; function closeSession(){ if(confirmclose) { return "close"; } } window.onbeforeunload = closeSession; <a href="http://rtscntl/" rel="nofollow">test</a> <a href="http://www.google.com/" rel="nofollow">Google</a> fewfwef --> <!–

var confirmclose = true;
var sucess = false;
var ajaxSubmit = false;

function closeSession(){
if(confirmclose) {
return “close”;
}
}

window.onbeforeunload = closeSession;

test

Google
fewfwef

–>

]]>
By: Bharani http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-192553 Bharani Fri, 02 Dec 2011 14:09:46 +0000 http://amazing-development.com/?p=333#comment-192553 var confirmclose = true; var sucess = false; var ajaxSubmit = false; function closeSession(){ if(confirmclose) { return "close"; i want to find retrun value and tehn use ajax function to update isActive field in user table } } window.onbeforeunload = closeSession; <a href="http://rtscntl/" rel="nofollow">test</a> fewfwef i need all these happen only when browser close [x] is clicked var confirmclose = true;
var sucess = false;
var ajaxSubmit = false;

function closeSession(){
if(confirmclose) {
return “close”; i want to find retrun value and tehn use ajax function to update isActive field in user table
}
}

window.onbeforeunload = closeSession;

test

fewfwef

i need all these happen only when browser close [x] is clicked

]]>
By: Bharani http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-192523 Bharani Fri, 02 Dec 2011 09:10:55 +0000 http://amazing-development.com/?p=333#comment-192523 var confirmClose = true; var keyCode = 0; function closeSession(evt){ if(confirmClose){ return 'Bharani'; i want to find retrun value and tehn use ajax function to update isActive field in user table } } window.onbeforeunload = closeSession; <!-- doSomething(event);--> <a href="http://rtscntl/" rel="nofollow">test</a> <a href="http://www.google.com/" rel="nofollow">Google</a> i need all these happen only when browser close [x] is clicked var confirmClose = true;
var keyCode = 0;

function closeSession(evt){
if(confirmClose){
return ‘Bharani’; i want to find retrun value and tehn use ajax function to update isActive field in user table
}
}

window.onbeforeunload = closeSession;

<!– doSomething(event);–>

test

Google

i need all these happen only when browser close [x] is clicked

]]>
By: Bharani http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-192498 Bharani Fri, 02 Dec 2011 07:15:05 +0000 http://amazing-development.com/?p=333#comment-192498 i need all these happen only when browser close [x] is clicked i need all these happen only when browser close [x] is clicked

]]>
By: Bharani http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-192497 Bharani Fri, 02 Dec 2011 07:08:05 +0000 http://amazing-development.com/?p=333#comment-192497 function closeSession(){ if(confirmclose) { return test(); /// i want to find retrun value and tehn use ajax function to update isActive field in user table } } if the possible to find retrun value to call the ajax function function closeSession(){
if(confirmclose) {
return test(); /// i want to find retrun value and tehn use ajax function to update isActive field in user table
}
}

if the possible to find retrun value to call the ajax function

]]>
By: Bharani http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-192490 Bharani Fri, 02 Dec 2011 06:49:36 +0000 http://amazing-development.com/?p=333#comment-192490 if i using this code if user click browser close means ajax called and browser also closed pls give solution or sample page to how to use ajax when return value find to call ajax function closeSession() { //alert(confirmClose); if (confirmClose) { //if (confirm('Are you want to close the page?')) { ////alert('/Login.aspx/hostoruser_Logout'); //} else { return; } return test(); } } var sucess = false; var ajaxSubmit = false; function test() { if (sucess == true) return "Are you want to close the page?"; if (ajaxSubmit == false) { ajaxSubmit = true; $.ajax({ asyn: false, url: '/BrowserClose.aspx', type: 'Post', data: {}, contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { //alert('sucess'); sucess = true; }, error: function (xhr, ajaxOptions, thrownError) { //alert(xhr.status); //alert(xhr.statusText); //alert(thrownError); } }); } setTimeout(test(), 200); } window.onbeforeunload = closeSession; this is code right now i use but it says "Too much of recursion" if i using this code if user click browser close means ajax called and browser also closed pls give solution or sample page to how to use ajax when return value find to call ajax

function closeSession() {
//alert(confirmClose);
if (confirmClose) {
//if (confirm(‘Are you want to close the page?’)) {
////alert(‘/Login.aspx/hostoruser_Logout’);
//} else { return; }
return test();
}
}

var sucess = false;
var ajaxSubmit = false;

function test() {
if (sucess == true)
return “Are you want to close the page?”;

if (ajaxSubmit == false) {
ajaxSubmit = true;
$.ajax({
asyn: false,
url: ‘/BrowserClose.aspx’,
type: ‘Post’,
data: {},
contentType: “application/json; charset=utf-8″,
dataType: “json”,
success: function (msg) {
//alert(‘sucess’);
sucess = true;

},
error: function (xhr, ajaxOptions, thrownError) {
//alert(xhr.status);
//alert(xhr.statusText);
//alert(thrownError);
}
});
}

setTimeout(test(), 200);
}

window.onbeforeunload = closeSession;

this is code right now i use but it says “Too much of recursion”

]]>
By: schlumpf http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-192376 schlumpf Thu, 01 Dec 2011 18:00:28 +0000 http://amazing-development.com/?p=333#comment-192376 well, *I* do answer them, if you, dear Bharani, tell me what the problem is? Is there any way I can reproduce it in my own browser/webserver? well, *I* do answer them, if you, dear Bharani, tell me what the problem is? Is there any way I can reproduce it in my own browser/webserver?

]]>
By: Frank Spychalski http://amazing-development.com/archives/2008/11/25/javascript-close-hook-for-browser-window/comment-page-1/#comment-192352 Frank Spychalski Thu, 01 Dec 2011 16:17:39 +0000 http://amazing-development.com/?p=333#comment-192352 Sorry mate, I don't handle "pls give me soution" requests. Sorry mate, I don’t handle “pls give me soution” requests.

]]>