By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Firefox close forbid

P: n/a
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.
Oct 3 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Oct 3 '05 #2

P: n/a
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.
Oct 3 '05 #3

P: n/a
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
Oct 3 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.