Below is the code:
<script
language="javascript"
type="text/javascript">
window.onbeforeunload = function()
{
return "Are you sure want to close";
}
</script>
Above code will execute on every postback. The alert message will appear on any click event like button,links, hyperlinks etc
If we don't want this message on click of buttons and links we have to implement below code :
<script
language="javascript"
type="text/javascript">
window.onload = function() {
var btnRelease = document.getElementById('<%=
btnRelease.ClientID %>');
//Find the button set
null value to click event and alert will not appear for that specific button
function setGlobal() {
window.onbeforeunload = null;
}
$(btnRelease).click(setGlobal);
// Alert will not appear for all links on the page
$('a').click(function()
{
window.onbeforeunload = null;
});
window.onbeforeunload = function()
{
return
'Are you sure you want to leave this page?';
};
};
}
</script>
Now alert/confirm message will appear only on back button of browser.
Former memberPosted Nov 27, 2013, 11:00 PM
window.onbeforeunload = function() { return ""; } U can use this event if u try to close the browser it will prompt a confirm message.
Ramesh RPosted Nov 27, 2013, 10:26 AM
How to know if entire application closed(browser closed) with out logout?please suggest if any Javascript event exist to know?