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

  • Home
  • SEARCH
  • 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 542403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:26:35+00:00 2026-05-13T10:26:35+00:00

When a user leaves one page of my website, there should be a warning

  • 0

When a user leaves one page of my website, there should be a warning message which gives the user the option to stay on the page:

“Are you sure that you want to close this page?”

It doesn’t matter if the next page is an internal or external page.

I thought this could be done with the onUnload event handler, couldn’t it?

<body onunload="confirmClose()">

The confirmClose() function must then show a message box with two buttons so that the user can choose between “Really leave” or “Stay”.

function confirmClose() {
    return confirm('Really leave this page?')
}

But this function can’t stop the unload, right?

Do you have a solution for my problem? Thanks in advance!

  • 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-13T10:26:35+00:00Added an answer on May 13, 2026 at 10:26 am

    You can add an onbeforeunload event. Note that it can only return a text string to include in the dialog the browser will display when the event is called. You can’t tweak the dialog beyond that, nor can you trigger your own confirm as you’re trying to do.

    I’d note that this is very, very annoying behaviour except in a few specific situations. Unless you’re saving me from significant data loss with this, please don’t do it.

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

Sidebar

Related Questions

Here's the situation. Multi-million user website. Each user's page has a message section. Anyone
I need to send a post request when the user leaves the page in
When a user leaves a page, I need to ask him if he wants
I'm currently trying to make a page via php which allows the user to
What is the best way to detect if a user leaves a web page?
I have a page in my Django app that needs to do one of
I want to send an ajax request when a user leaves a page or
I am searching for a way to know when the user leaves the page
I need to do some processing after my user leaves a text field. I
I have a asp.net/c# web app. When do user leave a certain page, I

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.