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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:58:41+00:00 2026-06-11T21:58:41+00:00

What I am trying to do is make a pop-up box any time a

  • 0

What I am trying to do is make a pop-up box any time a page exits or is navigated away from. Right now I have

<script type="text/javascript">
function box()
{
    var r=confirm("Message");
    if (r==true)
    {
        window.location.href="yes.html";
    }
    else
    {
        window.location.href="no.html";
    }
}
</script>


<body onunload="box();">

I have 2 problems with this:

  1. It only shows the box if you actually navigate away from the page, refresh, new url etc. If you exit the tab or browser, the box doesnt pop up.

  2. No matter what button you press, it just sends you where you tried to go originally, it never sends you to no.html or yes.html.

Could someone tell me how this is possible?

  • 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-11T21:58:43+00:00Added an answer on June 11, 2026 at 9:58 pm

    Try this:

    <script type="text/javascript">
      window.onbeforeunload = confirmExit;
      function confirmExit()
      {
          setTimeout(function() {
            setTimeout(function() {
               window.location.href="yes.html";
            }, 1000);
        },1);
        return "Message";
      }
    </script>
    

    You can only catch the stay on the page option, you cannot override a user leaving the page. similar to: Way to know if user clicked Cancel on a Javascript onbeforeunload Dialog?

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

Sidebar

Related Questions

I have a pop up dialog box and I am trying to make it
I have been trying to make the FullCalendar events use Facebox to pop up
Im trying to make a pop-up like window using jquery and its modal box.
I'm trying to make a pop up message box with Hello World written on
I'm currently trying to make a small application that performs different duties. Right now
I'm trying to make a pop up box, which gets invoked on clicking a
I am trying to make a box pop up when i click on it.
I am trying to make a custom dialog box LayoutInflater li = LayoutInflater.from(this); View
I'm trying to make a queue struct that have push and pop functions. I
Trying to make the infamous checkall checkbox for dynamically created rows from a MySQL

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.