How to capture window close[x] button with Jscript??

Discussion in 'JavaScript' started by dethlon, Jun 20, 2006.

  1. #1
    hi guys..
    i have a problem with closing up the IE window close button....
    i am trying to run some script/command (updating some user status in database) when the user tried to close the windows close[x] button....

    i have search for the internet and found out there is "onUnload" method which can be put on the HTML body tag. but i have found that this method has some weaknesses,such as when the page is refresing or when the user press F5, this unload event will also be called....(in other word, i only want the onUnload even is called when the user try to log off or close the windows by clicking the windows button)..

    so i wonder whether there is any script/method can reliably capture the windows close[x] button to run certain code/commands before the windows is closing....

    Another thing is....
    i wanna ask whether there is anyway i can actually do :
    1. disable the user rightclick function?
    2. or disable the refresh function/ user F5 button?

    if anyone have any clues on how to do any of them pls tell me....
    thanks alot~~

    anydoubt about my questions pls email me....
    my email : susanto_wang@yahoo.com
     
    dethlon, Jun 20, 2006 IP
  2. sllik

    sllik Active Member

    Messages:
    419
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    I think the onUnload event is your only option. I know you can disable the right-click function with some javascript, but you surly can't disable the refresh function.
     
    sllik, Jun 24, 2006 IP
  3. balajiora

    balajiora Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Add this oncontextmenu="return false;" in body tag to disable the right click.

    I am facing the same issue with window.unload. Did you guys got the solution?
     
    balajiora, Oct 8, 2007 IP