Forum Moderators: open

Message Too Old, No Replies

Browser Closing in Netscape and IE

         

pallavr

10:43 am on Dec 28, 2006 (gmt 0)

10+ Year Member



Hi All,

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

Fotiman

5:25 pm on Dec 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You might need to look into using the onbeforeunload event handler. But this will be called whether or not the user is closing the window, navigating to a different page, or using the back/forward buttons in their browser. So I'm not sure if that's what you're looking for.

window.onbeforeunload = yourFunc;

pallavr

5:36 am on Dec 29, 2006 (gmt 0)

10+ Year Member



Hi,
Thank you for your reply.
I have tried to use this before :

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