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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:02:35+00:00 2026-05-31T21:02:35+00:00

I have an onbeforeunload event : $().ready(function() { window.onbeforeunload=function() { return haha }; });

  • 0

I have an onbeforeunload event :

$().ready(function() { 
  window.onbeforeunload=function() { return "haha" };
});

And my links are like this (ajax web site) :

<a href="#pageX" /> 

But the onbeforeunload is never called. What can i do ?

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-31T21:02:36+00:00Added an answer on May 31, 2026 at 9:02 pm

    I’m guessing since you’re trying to bind to the onbeforeunload and return a string, that you’re looking to provide the user with an “Are you sure you want to leave this page” dialog on an AJAX site.

    In which case you probably need to go about this a little differently by binding a click handler onto the links. So you can prevent the hash change until the confirmation is made.

    Something like:

    $('a[href^="#"]').live('click',function(e){
        if( //should we be confirming first? ) {
            //put your confirmation code here either using default JS windows or your own CSS/jQueryUI dialog boxes
            // this code should either cache the url of the link that was clicked and manually update the location with it when the user confirms the dialog box (if you're using JQUI windows) or simply use JS confirmation boxes and based on the response, all you need to do is return; and the link click will handle normally
            e.preventDefault(); //prevent the link from changing the hash tag just yet
            e.stopImmediatePropagation(); //prevent any parent elements from firing any events for this click
        }
    } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one php page like this <script type=text/javascript src=js/jquery.min.js></script> <script type=text/javascript> window.onbeforeunload =
I have this jQuery code; $(function () { $(window).unbind(beforeunload); $(window).bind(beforeunload, function () { return
I have a function: window.onbeforeunload = function () { $.get(Handler.ashx, mode=saveuser&user= + $(#username).text(), function
I have a function like this to prompt the user to confirm they want
I have set up in javascript: var onBeforeUnloadFired = false; window.onbeforeunload = function (sender,
We are using window.location.href to navigate the user to a page. Also, we have
I am hooking the window.onbeforeunload event in an aspx page. I need that not
I have the following code to call count_visit.php on onbeforeunload event. That works great.
Setup I've attached an event to the 'window' object, and I would like to
I have an onbeforeunload event handler attached to the page which executes every time

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.