Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8791761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:53:14+00:00 2026-06-13T22:53:14+00:00

I tried window.onbeforeunload but it doesn’t seem to work. Any help? I have a

  • 0

I tried window.onbeforeunload but it doesn’t seem to work. Any help?

I have a cookie that tracks if the user logged in.

function handleLoginRegSuccess(){
    $.cookie('loginStatus', "ON", { expires: 1, path: '/'});
    showBusyMessage();
    goToIndex();
}

This is what I tried, but it doesnt work.

window.onbeforeunload = function(e) {
    if(userLoginStatus()=="ON"){
        requestLogout();
        $.removeCookie('loginStatus');
        return "test";
    }
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:53:15+00:00Added an answer on June 13, 2026 at 10:53 pm

    So, to answer your question directly, onbeforeunload needs a return value to actually work, at which point it’ll prompt the user with that string and they’ll get a confirm box.

    More details in this stack answer: How can I override the OnBeforeUnload dialog and replace it with my own?

    What you might consider instead, is to have a session timeout that logs the person out, or (more aggressively) a heartbeat from the client that keeps them logged in (via ajax). When the heartbeat fails to fire, they get logged out.

    You can also use the onunload event, if you’re not trying to interact w/ the user at all (as your sample code seems to not do): http://msdn.microsoft.com/en-us/library/ie/ms536973(v=vs.85).aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried window.getComputedStyle and currentStyle,but it not work except the chrome. Please look
I have tried window.location.href without doing any submission it works window.location.href=http://www.google.com; But how about
i tried below javascript and it does open the url in open window but
I've tried using a global hook but the hookprocedure only recieved window procedure messages
I want to capture the browser window/tab close event. I have tried the following
How do I send a period using sendkeys? I have tried: System.Windows.Forms.SendKeys.SendWait({.}); System.Windows.Forms.SendKeys.SendWait(.); but
I am hooking the window.onbeforeunload event in an aspx page. I need that not
What is the equivalent code of Response.Redirect(~/Account/Login.aspx); in javascript? I tried : window.location=~/Account/Login.aspx but
Possible Duplicate: Capturing result of window.onbeforeunload confirmation dialog I want to make user confirm
I think I've tried everything to get the right window height in IE7 but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.