Firefox close forbid

S

Skot

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.
 
R

RobG

Skot said:
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;};
 
M

Michael Winter

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
 
R

RobG

Michael said:
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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top