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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:36:49+00:00 2026-06-12T01:36:49+00:00

I am trying to get window.confirm to work with a script I am working

  • 0

I am trying to get window.confirm to work with a script I am working with however it doesn’t seem to wanna work . What happens is if the person presses cancel it still runs the code, And sadly now the way i wrote the code the popup box won’t even show up in chrome. Not sure why though I can remove the window.confirm method and it will still show a popup box but it will just run the script regardless of which choice you make. Here is the code , Thank you for your assistance.

var validNavigation = false;

function wireUpEvents() {

var dont_confirm_leave = 0; to be able to leave withou confirmation
var leave_message = 'Leaving the page will terminate your Self-Service or Kiosk session.';

function goodbye(e) {
if (!validNavigation) 

    function goodbye() = {
    var x = window.confirm("Leaving the page will terminate your Self-Service or Kiosk session.")
    if (x)
    {
    window.onunload=leave;
    }    
    else            {
    return "" ;
    }
    }}

function leave() {
    if (!validNavigation) {
    killSession();
    }
    }

    //set event handlers for the onbeforeunload and onunloan events
    window.onbeforeunload=goodbye;
    //window.onunload=leave;

            }
    // Wire up the events as soon as the DOM tree is ready
    jQuery(document).ready(function() {
    wireUpEvents();
    });
  • 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-12T01:36:51+00:00Added an answer on June 12, 2026 at 1:36 am

    You can’t stop someone from leaving the page – if they want to leave, they can. Stopping this event from propogating in the usual fashion doesn’t work. The way to get a popup message to display (which will usually be surrounded by browser supplied text) is to return your string from the function fired by onbeforeunload. Try this:

    function goodbye() {
      if (!validNavigation)
        return "Are you sure you want to leave";
      else
        return "";
    }
    window.onbeforeunload = goodbye;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the window.focus() function to work with no luck. Take a
Trying to get 100% height based on window size. <script> $(document).ready(function(){ var contHeight =
Trying to get getch() working to capture key press. #include <curses.h> ... ... WINDOW
I've been trying to get a window to show up asking the person to
I am trying to get the window handles to a Delphi application from an
I'm trying to get a window's XUL text as a String in Javascript. I
I'm trying to get the location of Window's Local AppData folder in a version-agnostic
I am trying to get the handle of a window from a process. Now,
I'm trying to get every widget to scale with change in window size. I
I'm trying to get the height of a html window's content. This is the

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.