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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:44:28+00:00 2026-06-12T05:44:28+00:00

I have a massive Javascript file capturing various keydowns on various screens of an

  • 0

I have a massive Javascript file capturing various keydowns on various screens of an application. I always use return false(); to prevent the default keydown action from occurring, which works great.

However, on this particular keydown, there is a confirm() box before the return false;. If I hit C, the confirm() dialogue comes up. If I move that out of the way, underneath it, the c has already been written to the text box.

How can I successfully suppress the keydown? This is only required to work in Chrome.

document.onkeydown = keyDown;

function keyDown()
{
    switch(window.event.keyCode)
    {
        case(67):
            if(confirm('You have unsaved data! Press OK to Save or Cancel to Discard')) {
                alert('Do something...');
            }
            else {
                return false;
            }
            window.location = '/invoice-12345';
            return false;
        break;
    }
}
  • 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-12T05:44:30+00:00Added an answer on June 12, 2026 at 5:44 am

    You can delay the confirm using setTimeout.

    document.onkeydown = keyDown;
    
    function keyDown()
    {
        switch(window.event.keyCode)
        {
            case(67):
                setTimeout(function() {
                    if(confirm('You have unsaved data! Press OK to Save or Cancel to Discard')) {
                        alert('Do something...');
                    }
                    else {
                        return false;
                    }
                    window.location = '/invoice-12345';
                }, 0);
                return false;
            break;
        }
    }
    

    jsFiddle

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

Sidebar

Related Questions

I have a massive XML file. However, I'm only interested in a single small
I have a massive viewstate hidden field that is causing my application to be
I am importing massive amounts of data from Excel that have various table layouts.
I have a massive, unfamiliar Java codebase that I need to use in one
I have a massive problem: I have a WPF application that makes a WcF
Let's say we have a massive CSS file that is used to style the
I have massive directories, and I would like to read all the files as
I have a massive table with thousands of rows. Each row has a unique
I have a massive set of files (4000+) that are in an old Apple
Im using wordpress for my website and i have a massive amount of data

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.