I have problem with this function. I will explain –
I must execute function if user closes browser. This function is write in JavaScript- saveCookieScriptPrefOnLogOut().
I have this solutions (I writed this using info from StackOverFlow):
var inFormOrLink;
$('a').live('click', function() { inFormOrLink = true; });
$('form').bind('submit', function() { inFormOrLink = true; });
$(window).bind('beforeunload', function(eventObject) {
var returnValue = undefined;
if (! inFormOrLink) {
saveCookieScriptPrefOnLogOut();
}
saveCookieScriptPrefOnLogOut();
return true;
});
Problems with this solution is: every browser display windows with question “Do you really want to close?”
I have to hide this information/window. Second problem (less important but still) – FF and IE runs this function when I click on Link or form submit. I need to ignore a links and form submit.
solution must be crossbrowser solution (IE, Chrome, FF on windows. The most important is IE). I can use PHP and javascript.
Can you give me any answer how I solve these problems?
Try this:
If you return
undefinedfrom the event handler (noreturnstatement implicitly returnsundefined), the dialog will not appear.. Also, you calledsaveCookieScriptPrefOnLogOutregardless ofinFormOrLink.