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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:39:44+00:00 2026-06-15T12:39:44+00:00

How to prompt when user typed something in the textbox and unknowingly close the

  • 0

How to prompt when user typed something in the textbox and unknowingly close the browser?

Also if the user doesn’t type anything in the input field and if close the browser, the browser should close without prompting. Browser should prompt only if the user changed something in the field. If I use onbeforeunload event, it promts for everything even when saving the page. Is there any way to solve my problem in javascript. Please help by giving me apt codes.

  • 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-15T12:39:45+00:00Added an answer on June 15, 2026 at 12:39 pm

    Check this link: https://web.archive.org/web/20211020134123/https://www.4guysfromrolla.com/webtech/100604-1.shtml

    It gives you information on how to handle onbeforeunload event.

    The idea is to have a global flag on the page. When any change is done to the fields, this flag is set to true. When clicked on save button, then this flag needs to be set to false.

    In the onbeforeunload event, check whether the flag is true, then show the message accordingly.

    var needToConfirm = true;
    
    window.onbeforeunload = confirmExit;
    function confirmExit()
    {
        if (needToConfirm)
        {
            // check on the elements whether any change has been done on the fields.
            // If any change has been done, then set message here.
        }
    }
    
    function saveClicked()
    {
        needToConfirm = false;
    }
    

    Another way of doing the things, would be to set the needToConfirm flag when any change is made to the fields via onchange events.

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

Sidebar

Related Questions

I want to prompt the user that something special has happened, so I want
I have a program that allows a user to type JavaScript in a textbox,
How to use intent to prompt user to choose finish action with to choosing
Is it possible, in Javascript, to prompt user for downloading a file that isn't
I prompt the user if they want to order fish, once they are done
I am currently making a program which is supposed to prompt the user to
I'm trying to make a script that will prompt the user and wait for
I have a standalone application in which I have to prompt the user with
I start out with an empty list and prompt the user for a phrase.
I was wondering if it is possible for a program to prompt the user

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.