/    Sign up×
Community /Pin to ProfileBookmark

An Innovative Trap Window for Close Event

I am currently having some problems with a java script that I am developing.

  • So far this has all been completed.
    The javascript is geared to make a user aware that they are clicking the X (Close Button) A popup message comes up making the user aware of what they have done. To this they can either click O.K to continue closing the page or Cancel to stop closing the page.
  • The Problem
    The next thing I want to do is add extra functions depending on the users choice. So basically I want to detect the users Choice, whether they clicked on O.K or Cancel so that I can assign Codes correspondingly

    So for example in this project.
    When the User clicks O.K to quit the program, this should be able to send a procedure to log-off from the system. What I need is to be able to detect that the user has clicked O.K so that I can do this.

    So I want something Like

    if event.returnValue = True
    — (Call Log-Off Procedure Code)

    The problem is I Cant get anything like that to work, below listed is the code that I am using, plus a few comments which state what I want to do more clearly in the code.
    I want to thank anyone in advance for looking at the problem

    [code=php]
    <BODY onbeforeunload=”HandleOnClose”()>
    <Script Language=”javascript”>
    <!–

    function HandleOnClose()
    {
    if (event.clientY < 0 )
    {
    event.returnValue = ‘You are going to leave the page press O.K to Log-Off Cancel to return to the page’;

    — At this point I want something to say
    — if event.returnValue=true then call log-off code
    — Or is there any other way to do without using the returnValue
    — statement.

    }
    }
    //–>
    </script>

    [/code]

    to post a comment
    JavaScript

    8 Comments(s)

    Copy linkTweet thisAlerts:
    @FangSep 20.2004 — Try [URL=http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onbeforeunload.asp]onbeforeunload[/URL]
    Copy linkTweet thisAlerts:
    @burningmoneyauthorSep 20.2004 — First of all Thank you 'Fang' for your contribution.

    To be honest I cant quite understand your response as I have already used an 'onbeforeunload' command in the body. And have correspondingly used the Event.returnValue statements.

    What I require is to detect the users choice if they clicked O.K or clicked CANCEL. If that can be done I can then use a simple 'if' statement to tell it to log-off or send a message somewhere, but the principle of my problem is that I cannot find a way to see if the user clicks O.K or Cancel.

    Have you any further Suggestions??
    Copy linkTweet thisAlerts:
    @FangSep 20.2004 — Sorry I missed that.

    This was discussed [URL=http://www.webdeveloper.com/forum/showthread.php?s=&threadid=26261&highlight=onunload]here[/URL], I don't believe there is a solution, perhaps with PHP sessions.
    Copy linkTweet thisAlerts:
    @burningmoneyauthorSep 20.2004 — As always Fang thank you for your contribution.

    Right, lets think out of the ball park here... Ummm

    Is there a code to stop a window from being closed. So if I click the X (Close button) and choose via an option not to close it stop it being closed.

    This should be without the use of the Event.returnValue statement

    So if I click the 'X' close button and I have a prompt asking me if I want to exit or not (a standard window.alert prompt) for arguments sake. And I click Cancel is there any sort of code that will stop the page from closing??


    So basically.

    Click X

    Prompt: Do you wish to close

    Click Cancel

    The statement clears and I am returned to the page without any further prompts

    What I am looking for is if I can utilise a simple alert statement to get the user response (O.K and Cancel), which I can do, I would then be able to fill in the codes for logging off if necessary?
    Copy linkTweet thisAlerts:
    @FangSep 20.2004 — Click X : only [I]event.returnValue[/I] false (Cancel) can prevent window closure.
    Copy linkTweet thisAlerts:
    @burningmoneyauthorSep 21.2004 — I was afraid you were going to say that...

    So back to my orginal point, is there a way you can detect if the user has clicked 'O.K' or 'Cancel' when the dialog box apperars.

    The closest match I have found is


    If (event.returnValue)event.retunValue=true

    {


    But once again that does not do what it is supposed to???



    Thanks again Fang
    Copy linkTweet thisAlerts:
    @FangSep 21.2004 — If "OK" has been pressed the browser will just close.

    There is no further interaction possible, no further flow in the function, just an "exit".

    From a security point of view it is logical. Otherwise you could prevent a user from closing his browser, he would have to switch his computer off.
    Copy linkTweet thisAlerts:
    @burningmoneyauthorSep 21.2004 — Sometimes security is a real pain...

    O.K thanks Fang for all your intricate knowledge, I think I will will leave this as a no hope scenario.

    If anyone else has an idea no matter how vague, please let me know.
    ×

    Success!

    Help @burningmoney spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.23,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...