I am using Ajax tabcontainer. i want to restrict the onbeforeunload event being fired on Ajax TabContainer. On click of one of the tab of TabContainer i am getting the alert/confirm message box which i have return in Onbeforeunload function.
The alert occurs because on tab click i have written C# code so postback occurs.
JavaScript
$('a').click(function() {
window.onbeforeunload = null;
});
window.onbeforeunload = function() {
return 'Pending changes will be lost unless they are saved first.'
'Are you sure you want to leave this page?';
};Code
Thanks in advance
Abhishek JainRank #1,062 · 1.8K reputationPosted Aug 13, 2013, 5:38 AM EDT
So what i am proposing will not look so good but that is how you have to handle it
var isTabClicked = false;
$('a').click(function() {
isTabClicked = true;
});
window.onbeforeunload = function() {
if(!isTabClicked)
{
return 'Pending changes will be lost unless they are saved first.'
'Are you sure you want to leave this page?';
}
};
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 13, 2013, 7:29 AM EDT
Try like this
Regards,
Iftikar
Sravan Kumar2 reputationPosted Feb 2, 2015, 5:38 AM EST
I am exactly struck at the same situation.
Thanks in advance