asifone
April 2nd, 2009, 12:22 PM
Hi,
I have been stuck with this requirement for past 1 week , lets get started .
When user comes on to the page , i have to force user to complete the details wihtout navigating or clickin gon any other menu.
My requirement is as user tries to click on any other menu without saving his details...we should throw him with alert('please save before navigating anywhere else') and after clicking OK button,... force him to stay back on the same page and do not allow him to navigate to other page.
<script type='text/javascript'>
function showalert()
{
alert('please save before navigating anywhere else');
return false;
}
if(window.body)
window.body.onbeforeunload = showalert;
else
window.onbeforeunload = showalert;
</script>
PROBLEM:---
As i return false after alert ...the onbeforeunload displays it confirm box with "false" asa string or meaage in confirm box....here user can click OK buttton and navigate away.I ave to force user to stay on same page , fill details ,,click SAVE and then you can navigate.
I have to write the function in onbeforeonload event only as i cannot capture it anywhere else..and this event gives me confirm box...i only want on this event to show myalert
and stay then an there .
I cannot use history.go(-1) for security reasons..i have tried window.locatoin.reload() ..but here it shows my alert twice even before reloading.?
Please help me
Any help would be greatly appreciated.
Thanks!!!!!!
I have been stuck with this requirement for past 1 week , lets get started .
When user comes on to the page , i have to force user to complete the details wihtout navigating or clickin gon any other menu.
My requirement is as user tries to click on any other menu without saving his details...we should throw him with alert('please save before navigating anywhere else') and after clicking OK button,... force him to stay back on the same page and do not allow him to navigate to other page.
<script type='text/javascript'>
function showalert()
{
alert('please save before navigating anywhere else');
return false;
}
if(window.body)
window.body.onbeforeunload = showalert;
else
window.onbeforeunload = showalert;
</script>
PROBLEM:---
As i return false after alert ...the onbeforeunload displays it confirm box with "false" asa string or meaage in confirm box....here user can click OK buttton and navigate away.I ave to force user to stay on same page , fill details ,,click SAVE and then you can navigate.
I have to write the function in onbeforeonload event only as i cannot capture it anywhere else..and this event gives me confirm box...i only want on this event to show myalert
and stay then an there .
I cannot use history.go(-1) for security reasons..i have tried window.locatoin.reload() ..but here it shows my alert twice even before reloading.?
Please help me
Any help would be greatly appreciated.
Thanks!!!!!!