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 812277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:10:43+00:00 2026-05-15T01:10:43+00:00

When I close my page on some browser I want a message box to

  • 0

When I close my page on some browser I want a message box to appear and to ask me if I really want to close the page or not, with two buttons and if I click No then this tab won’t be closed.

How can I do that?

  • 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-05-15T01:10:44+00:00Added an answer on May 15, 2026 at 1:10 am

    You need to listen on the beforeunload event.

    Here’s a kickoff example:

    window.onbeforeunload = function() {
        return "Hey, you're leaving the site. Bye!";
    };
    

    This message will show up in kind of a confirmation dialogue. This message will show up right before the client unloads the page. That can be a browser close, but that can also be a simple navigational action like clicking a link or submitting a form in the page!

    You would most probably also like to turn it off (just set to null) whenever an internal link is clicked or an internal form is submitted. You namely don’t want to annoy endusers with unintuitive behaviour. You can do that by listening on the click event of the desired links and the submit event of the desired forms. jQuery may be of great help here since it does that in crossbrowsercompatible way so that you don’t need to write >20 lines of JS code for this:

    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>
        window.onbeforeunload = function() {
            return "You're leaving the site.";
        };
        $(document).ready(function() {
            $('a[rel!=ext]').click(function() { window.onbeforeunload = null; });
            $('form').submit(function() { window.onbeforeunload = null; });
        });
    </script>
    

    You only need to give all external links the defacto standard attribute rel="ext" to denote that those are external links.

    <a href="http://google.com" rel="ext">Google</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to trigger some code when page action or browser action popup gets
I need to logout on close page or on close browser ... as usual
I want to alert a user while the user tries to close the browser
So i have a really weird problem with a knockoutjs click binding not getting
So i want to delete some files when a user closes the browser. I'm
Well, I want to login using cURL on some page. When i paste this
My Javascript needs to send some data to a server when the page closes,
So I have a web page where you can select text boxes and close
I am attempting to style a page and its very close but I am
I am having the following close button image tag in my page. img src=@@@HtmlEncode(LanguagePath)@@@/img/header/HEADER_SIGN_IN_POPIN_CLOSE.gif

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.