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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:15:03+00:00 2026-05-20T15:15:03+00:00

Whenever I add an event listener window.onbeforeunload , can I check where the page

  • 0

Whenever I add an event listener window.onbeforeunload, can I check where the page is being redirected to?
Or at least what the developer is trying to change.

The following is the thing that I really want:

This is what I do right now :

$(window).bind("beforeunload",function(){
      //I do what I want here
});

Now the issue is, I want to change the logic, when document.location.href = "mailTo:*" is being called. i.e. I do not want to do anything when doccument.location.href is called, so I want my logic to me like:

$(window).bind("beforeunload",function(){
       if(document.location.href has mailTo:)
       {
            //do nothing
       }
       else
       {
            //my old logic applies here
       }
});
  • 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-20T15:15:04+00:00Added an answer on May 20, 2026 at 3:15 pm

    You would need to add an event handler to Href links in your webpage,
    which set a variable on onclick = their href, you can read that variable in your onbeforeunload script. example code would be like this :

      var storeHref = null;
        $("a").bind("click", function(){
          storeHref = this.href;
          return true;
        });
    
      $(window).bind("beforeunload",function(){
           if(storeHref has mailTo:)
           {
                //do nothing
           }
           else
           {
                //my old logic applies here
           }
      });
    

    However if the redirection is happening due to some other event,like user entering a new url in the browser, or using a script, you can not detect the destination due to security reasons.

    Similar:
    How can i get the destination url in javascript onbeforeunload event?

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

Sidebar

Related Questions

I'm trying to add a google calendar gadget along with an event. However, whenever
I want to add an event listener that listens for whenever the text field
I making a custom button, and I need to add a PreviewKeyDown event, whenever
there's a swing JTextField , and I want to add a listener, so whenever
I'm trying to change the body background image whenever orientation changes. This seemed pretty
whenever i press on either up or down button i can check if those
Whenever I add paddingRight to a column in the flex grid, it adds the
whenever I add a new domain into my new Plesk control panel on my
I know that whenever you add/remove/modify any file in the App_Code, App_GlobalResources, and bin
I'm working on a word-press theme and whenever I add the code below to,

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.