Javascript : onbeforeunload -- conditional

I want to call onbeforeunload ONLY if a global variable indicates there is some unsaved work. Otherwise, there is no need to query (and possibly confuse) the user. The return function only serves to add text to the confirm window (eg setting it to false does not disable the popup).

The following ALMOST works, except that I can't control whether it calls the dialog box or not.


function quit(){

event.returnValue="Have you saved your work?"}



I also tried the format shown for the onunload event, but the onbeforeunload event always pops up the dialog.

My intent is to set a flag if data in a grid is changed, then only call the quit() function if the flag is true, and no dialog box if it is not true.

I also need the best way to create this flag (asp.net, vb.net) and toggle it.

Better yet:

The OPTIMAL reaction would be:

1. Only call the function if there is unsaved work


2. Continue & Loose Changes: Give a choice of continue without saving - thereby losing the changes (equivalent to the OK button)

3. Continue AFTER Saving: Programatically Click the existing save button I have already created to save the work, then continue to the chosen destination after the save/post is done.

4. Return to the work/Don't continue the move/close & don't save -- let the user review the work, then decide: (actually just cancel the unload)

## Deliverables

1) Complete and fully-functional working program(s) in executable form as well as complete source code of all work done.

2) Deliverables must be in ready-to-run condition, as follows (depending on the nature of the deliverables):

a) For web sites or other server-side deliverables intended to only ever exist in one place in the Buyer's environment--Deliverables must be installed by the Seller in ready-to-run condition in the Buyer's environment.

b) For all others including desktop software or software the buyer intends to distribute: A software installation package that will install the software in ready-to-run condition on the platform(s) specified in this bid request.

3) All deliverables will be considered "work made for hire" under U.S. Copyright law. Buyer will receive exclusive and complete copyrights to all work purchased. (No GPL, GNU, 3rd party components, etc. unless all copyright ramifications are explained AND AGREED TO by the buyer on the site per the coder's Seller Legal Agreement).

## Platform



Evner: ASP, Javascript, PHP

Se mere: javascript onunload destination, review javascript, javascript popup dialog, intent to hire form, intent to hire, better javascript, best javascript coder, javascript onbeforeunload conditional, javascript data format, event javascript, javascript quit, code review javascript, javascript receive data php, javascript add button, disable save, javascript post request, php global variable, cancel following request, cancel request following, popup javascript code

Om arbejdsgiveren:
( 182 bedømmelser ) Newport Beach, United States

Projekt ID: #3833032

Tildelt til:


See private message.

$4 USD på 1 dag
(5 bedømmelser)

5 freelancere byder i gennemsnit $24 på dette job


See private message.

$68 USD på 1 dag
(36 bedømmelser)

See private message.

$21.25 USD på 1 dag
(50 bedømmelser)

See private message.

$4.25 USD på 1 dag
(11 bedømmelser)

See private message.

$21.25 USD på 1 dag
(1 bedømmelse)