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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:53:21+00:00 2026-05-20T14:53:21+00:00

I have a Flex application where I want to give the user a warning

  • 0

I have a Flex application where I want to give the user a warning if they hit the back-button so they don’t mistakenly leave the app. I know this can’t be done entirely in Actionscript due to cross-browser incompatibility. What I’m looking for is just the Javascript implementation to catch the back-button.

Does anyone have a simple non-library cross-browser script to catch the back-button? I can’t seem to find a post that shows an example.

  • 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-20T14:53:21+00:00Added an answer on May 20, 2026 at 2:53 pm

    You can use the window.onbeforeunload event.

    window.onbeforeunload = function () {
       return "Are you sure you want to leave my glorious Flex app?"
    }
    

    The user can press okay to leave, cancel to stay.

    As you stated, this throws the alert any time the page changes. In order to make sure it only happens on a back button click, we have to eliminate the alert message whenever they’re leaving the page from natural, expected sources.

    var okayToLeave = false;
    
    window.onbeforeunload = function () {
       if (!okayToLeave) {
       return "Are you sure you want to leave my glorious Flex app?"
       }
    }
    
    function OkayToLeave() {
        okayToLeave = true;
    } 
    

    You’ll have the responsibility of setting the variable to true whenever they click a button or link that will take them from that page naturally. I’d use a function for unobtrusive javascript.

    Set your event handlers in the DOM ready:

    referenceToElement.addEventListener('onClick', OkayToLeave(), false);
    

    This is untested, but should point you in the right direction. Although it may seem like a nuisance to do this, I imagine it’s more complete functionality. It covers the cases where a user may click on a favorite, or be redirected from an external application.

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

Sidebar

Related Questions

I have a flex application showing a chart. I want to give user the
i have a simple chat application in flex 3 and i want to make
I have a Flex application, I want to scroll the page to bottom when
I have a flex application and I want to add a new custom component
I have a flex application, running with amfphp and connected to wamp, I want
I am writing a flex application and I have two Spark TextAreas. I want
I have a mapping application written in a flex/flash app. This app is used
We have a Flex web application. I want to load the swf file in
i have two flex applications and i want to pass the data from one
I have a portlet. Inside of this portlet I have Flex application that displays

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.