|
|
Firefox close forbid
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.
|
|
0
|
|
|
|
Reply
|
Skot
|
10/3/2005 12:00:46 AM |
|
Skot wrote:
> Hello,
> Is exiting a possibility to forbid the click on the close cross ?
No.
> Otherwise, can we put a js treatment in order to don't lose the informations
> on the form ?
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>
>
> Thanks, Skot.
>
>
--
Rob
|
|
0
|
|
|
|
Reply
|
RobG
|
10/3/2005 12:33:39 AM
|
|
On 03/10/2005 01:33, RobG wrote:
[snip]
> window.onbeforeunload = function() {alert('hi'); return false;};
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.
|
|
0
|
|
|
|
Reply
|
Michael
|
10/3/2005 12:47:29 AM
|
|
Michael Winter wrote:
> On 03/10/2005 01:33, RobG wrote:
>
> [snip]
>
>> window.onbeforeunload = function() {alert('hi'); return false;};
>
>
> 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.
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
|
|
0
|
|
|
|
Reply
|
RobG
|
10/3/2005 1:46:00 AM
|
|
|
3 Replies
227 Views
(page loaded in 0.055 seconds)
|
|
|
|
|
|
|
|
|