|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Other - Onbeforeunload and auto confirm pop up box
to start off, i have read various threads on this forum to try and find a solution, but after much testing of things i have read i still cant seem to fix my "problem".
Description of what happens: Developing in/for FF v2 (no attempts to develop for IE - per client specification) I have a DIV tag in my page (initially empty) that i fill with "alerts" to the user concerning errors or actions to be taken. (does the same as alert() basically but is not a popup and i can make it pretty ![]() For this i use css and the below JS function. Code:
function askOnCloseWindow() {
var alertfield= document.getElementById('alert');
var thestuff= "<p class='alertBox'><b>Confirmation:</b> <br> Please verify that you wish to close this interface window:<br><input type='button' value='Yes, close' onClick='javascript:window.close()'> <input type='button' value='No, keep window' onClick='javascript:clearAlertBox()'></p>";
alertfield.innerHTML= thestuff;
}
Problem: I want to try and ensure that a user doesn't accidentally close the window while busy with something. With my personal "close this window" button added it works fine: The small notice area (described earlier) appears asking if you really want to close the window or not. But i would like to do so with the window close(x) button as well. I have read up on using onunload and onbeforeunload (in this forum) and i have managed to get the "alert area" to appear, but i still get the "confirm" pop up box appearing as well. Code:
window.onbeforeunload = function (oEvent) {
closeme();
oEvent.returnValue = "i dont want this popup window!;
}
when using the window close(x) button this code calls the earlier shown function. I would like to know if it possible to NOT show the confirm box triggered by returning a value to onbeforeunload? THUS if the user uses the window close(x) button, the personalized alert area displays a yes or no button, but no confirm pop up displays. I have tried to not return anything to onbeforeunload but that just closes the window without anything happening. I don't want to control whether the window may close or not, i just want to make my own "confirm" box. And if there is a completely different way to do this, please direct me to where i must go! Hope this all makes some sense! and any help would be greatly appreciated.PS: I am aware that by calling window.close() in the "display area" (as indicated in first function listed above) it would most probably cause an endless loop of asking if you actually want to close the window, but will tackle that problem after i have solved this one! ![]() |
|
#2
|
|||
|
|||
|
Need Help
these codes work for IE, i need any script which can solve the problem for all browsers, currently trying to solve this problem for firefox and opera.
I need to able to give a popup message on close of the window, it will close the window if it returns true else be on the window. Currently for IE i am using the following code. <script language="javascript"> <!-- function HandleOnClose() { if (event.clientY < 0) { event.returnValue = 'Are you sure you want to leave the page?'; } } //--> </script> <BODY onbeforeunload="HandleOnClose()" > fdgd </BODY> Kindly help me. Thanks & Regards Upendra Kumar +91-9971396361 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Other - Onbeforeunload and auto confirm pop up box |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|