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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:29:19+00:00 2026-06-10T22:29:19+00:00

I’m using some function with jQuery, for example: $(window).one(‘beforeunload’, function() { //my code });

  • 0

I’m using some function with jQuery, for example:

$(window).one('beforeunload', function() {
//my code
});

But I really want to find out all about what has triggered this event and how.

I tried the following code:

$(window).one('beforeunload', function(e) {
alert(JSON.stringify(e));
});

But it raises exception about circular structure. Definitely though there must be some other way of differentiating and debugging through it.

How am I going to apply it?

I want to see what triggered this event, was it a link, a submitted form, a javascript, a page refresh, or a back and forth buttons or whatever, and it’s all fine in that case. BUT if it was triggered by a call to open an external application, I want to discard the event and return null.

Example of external application launch:

<a href="skype:your_skype_name?call" >

Any ideas?

SOLVED

This is how I solved it.

I just make some script link first, to gain more control over the event:

<a href="javascript:void(0)" id="skype_click_ok"

Then I create a global variable to store the state of beforeunload:

var dontunload=0;

Then I manually process the link, but setting location.href, and changing variable state:

$('#skype_click_ok').click(function(){
dontunload=1;
location.href='skype:marilynbrusas?call';
});

Now my actual beforeunload event, note the one() was also changed to bind():

$(window).bind('beforeunload', function() {
  if (dontunload==1) dontunload=0;  //if triggered from our skype - do nothing, yet  cancel state for the next call
  else {  //Do the actual code
          // Fade out, before leaving the page.
      $('html#my_html').stop(true,false).css('overflow','hidden').animate({opacity:0},2000);
      // Lock content with invalid image hack
          $('body#my_body').prepend(
        $('<div>').attr({style:'position:fixed;height:100%;width:100%;left:0;top:0;z-index:900100;background-image:url(in-your-face)'})
      );
          // unbind the event
      $(this).unbind('beforeunload');
  }
});

EDIT3

Actually it’s not solved. This trick does not work in IE and also the even triggers from javascript:void(0) links…

  • 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-06-10T22:29:20+00:00Added an answer on June 10, 2026 at 10:29 pm

    Using alert to display objects like events is fairly useless.

    Why don’t you try sending you event to the console?

    function(event) {
        console.log(event);
    }
    

    This way you can expand you event object and view it in a a tree like structure.

    EDIT As per you comments about the location of the event trigger: I haven’t testing this, but this could be a way of stopping your unload event.

    • Listen for click events for all a elements
    • Check the element clicked points to an external application (doesn’t start with http://)
    • If not, bind an event handler for beforeunload that cancels the event immediately
    • Otherwise unbind the previous handler

      $("a").click(function(event) {
        if(event.target.href.indexOf("http://") != 0) {
          $(window).on("beforeunload.override", function(e) {
            // Stop the 'beforeunload' event.
            return false;
          }
        }
        else {
          $(window).off("beforeunload.override");
        }
      }
      

    Notice that this example is using something call Event Namespacing. By specifying that we want to listen to the beforeunload event, but we have our own namespace called override, we can add and remove the event handler safely without removing all other listeners for the beforeunload event.

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I want to construct a data frame in an Rcpp function, but when I
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.