Forum Moderators: open
I have a requirement where the web page has filled data in a form and if the user accidently clicks the browser closing button then he should be prompted with a confirmation dialog before closing.
I call this method in the <body> unload event.I do not want the message to pop up when the user is clicking the <next> button to browse to another page.
This works wonderfully with IE 6.0 but fails in the case of Netscape6.2 it fails i am not getting the default message " Do you want to close the Window".
Any suggestions on how can i make it work on IE and Netscape in a similar fashion.
function dispConfirm(){
var con = confirm("Do you want to save the data before closing the window")
if(con){
window.close()
}
else
{
document.write("You pressed Cancel!")
}
}
function unLoadFnc()
{
if(window.screenLeft < 10004)
{
alert("Refresh Coordinate: "+window.screenLeft);
}
else
{
alert("Closing Coordinate: "+window.screenLeft);
dispConfirm();
}
}
Best Regards,
Pallavi
window.onbeforeunload = yourFunc;
function winUnload(e){
var msg = document.getElementById("");
//IE
if(document.all) {
event.returnValue = "This window is going to close";
return false;
}
}
window.onbeforeunload = function(e){
winUnload(e);
}
But the problem is the message pops up when the user navigates to another page from this page also in IE.
And the message does not appear in case of Netscape.It simply closes the window with no confirmation dailog.
I also found another problem in Netscape specification it states that that only
“windows which were opened with JavaScript can be closed by JavaScript”
Has anybody overcome this hinderance.
Best Regards,
Pallavi