Connecting Tech Pros Worldwide Help | Site Map

Firefox close forbid

Skot
Guest
 
Posts: n/a
#1: Oct 3 '05
Hello,
Is exiting a possibility to forbid the click on the close cross ?
Otherwise, can we put a js treatment in order to don't lose the informations
on the form ?

Thanks, Skot.


RobG
Guest
 
Posts: n/a
#2: Oct 3 '05

re: Firefox close forbid


Skot wrote:[color=blue]
> Hello,
> Is exiting a possibility to forbid the click on the close cross ?[/color]

No.
[color=blue]
> Otherwise, can we put a js treatment in order to don't lose the informations
> on the form ?[/color]

Firefox and Mozilla support 'window.onbeforeunload' (though it doesn't
seem to have made it into the on-line documentation yet) that allows you
to prompt a user to not close a window.


<script type="text/javascript">

window.onbeforeunload = function() {alert('hi'); return false;};

</script>

[color=blue]
>
> Thanks, Skot.
>
>[/color]


--
Rob
Michael Winter
Guest
 
Posts: n/a
#3: Oct 3 '05

re: Firefox close forbid


On 03/10/2005 01:33, RobG wrote:

[snip]
[color=blue]
> window.onbeforeunload = function() {alert('hi'); return false;};[/color]

A beforeunload listener should return a string. This string will be
displayed in a dialog box that asks whether the user wishes to navigate
away from the current document. So,

window.onbeforeunload = function() {return 'Hi';};

would be more appropriate.

You can't cancel the event programatically; the whole point is for the
user to handle it.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
RobG
Guest
 
Posts: n/a
#4: Oct 3 '05

re: Firefox close forbid


Michael Winter wrote:[color=blue]
> On 03/10/2005 01:33, RobG wrote:
>
> [snip]
>[color=green]
>> window.onbeforeunload = function() {alert('hi'); return false;};[/color]
>
>
> A beforeunload listener should return a string. This string will be
> displayed in a dialog box that asks whether the user wishes to navigate
> away from the current document. So,
>
> window.onbeforeunload = function() {return 'Hi';};
>
> would be more appropriate.
>
> You can't cancel the event programatically; the whole point is for the
> user to handle it.[/color]

Thanks Mike.

I couldn't find any documentation on the Mozilla site (it seems to be a
fairly recent inclusion), the Microsoft doco wasn't very clear - their
example used window.event.

Hopefully the following is better:


function savePrompt()
{
var unsavedData = true;

// Do some test to determine if there is unsaved data
// if unsavedData = true, message is shown
// if unsavedData = false, navigation is not interrupted

if ( unsavedData ){
var message = 'You have unsaved data.'
+ '\nLeaving this page without saving'
+ ' will cause the data to be lost';
return message;
}
}

window.onbeforeunload = savePrompt;



--
Rob
Closed Thread