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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:35:32+00:00 2026-05-24T05:35:32+00:00

The situation: I have a Grails webpage with two tables. One table displays a

  • 0

The situation: I have a Grails webpage with two tables. One table displays a persons information (including certain flags), and the second table has a list of flags with an “add button” that allows the user to add a given flag to themselves.

Now, there is a save button that, when clicked, pushes the current “state” of the users flags to our database. So I want to be able to display a prompt if there is unsaved information being displayed when a user tries to navigate to another part of the site. This is easy enough by using an existing isDirty boolean that each flag stores. I can just loop through the persons active flags and check if it is dirty or not. If the person contains at least 1 dirty flag, I need to display a prompt if they try to leave, because that data won’t be saved unless they explicitly hit the button.

The problem: There are many ways to navigate away from this page. I am using
<body onbeforeunload="checkForDirtyFlags();">, where checkForDirtyFlags() is a basic js function to check for any dirty flags. But here’s the thing – when a user adds or removes a flag, that causes a page reload because the way the page is setup is to redirect to a url like this:

"http://my.url/addFlag/123456"

The controller then knows to add the flag with id 123456 to the current person. This does NOT change where the person is in the website however, because the same page is still rendered (it just contains updated tables). So basically, when I see a URL with addFlag or removeFlag, I do not want to prompt the user if they are sure they want to navigate away from the page, because in the eyes of the user they are not leaving the page.

The question: Is there any way to determine what the target is during an onbeforeunload? So that I can have something like this in my javascript:

function checkForDirtyFlag() {
    if( justAdding ) { //We are just adding a flag. No prompt necessary
        //Don't do anything
    }
    else if( justRemoving ) { //We are just removing a flag. No prompt necessary
        //Don't do anything
    }
    else { // In this case, we want to prompt them to save before leaving
        alert('You have unsaved data on the page. Leaving now will lose that data. Are you sure you want to leave?');
    }
}

If any of this isn’t clear, please let me know and I’ll try and clear it up.

Thanks!

  • 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-24T05:35:33+00:00Added an answer on May 24, 2026 at 5:35 am

    I don’t think you can get the target location in unload event. What I’d do is bind the save/submit button to a function that disables the unload event if the button is pressed, therefore disabling the prompt. If the user tries to leave by pressing back etc, the unload event would fire.

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

Sidebar

Related Questions

Situation: I have some persons with certain skills and they can/might belong to more
Situation I have 5 Access DB files, each one has 10 tables, 40 queries
Situation: I have two tables, say 'master' and 'detail', where 'master' has two columns
Situation: I have a simple XML document that contains image information. I need to
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have the following situation: I have a certain function that runs a loop
Situation: I have two fixed-height divs, overflow set to hidden on both, and dynamic
I'm learning to use Grails and have run into a situation I don't understand
Situation: I have a multithreaded program written in C. If one of the threads
I have situation, where I want to read configuration file only one time, when

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.