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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:22:20+00:00 2026-05-25T20:22:20+00:00

I am having strange problem with jQuery (1.6.x). I have this simple call on

  • 0

I am having strange problem with jQuery (1.6.x). I have this simple call on my page:

window.onbeforeunload = function() { return 'Are you sure ?'; };

But it doesn’t work, because as I’ve found out, jQuery overwrites content of the window.onbeforeunload. In JS console, I can see that window.onbeforeunload contains piece of jQuery code:

function( e ) {
// Discard the second event of a jQuery.event.trigger() and
// when an event is called after a page has unloaded
return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ?
    jQuery.event.handle.apply( eventHandle.elem, arguments ) : undefined;
};

Is there a way I can find why and where jQuery overwrites my onbeforeunload function? When I try to run empty jsfiddle with just jQuery loaded and with my onbeforeunload function, it works as expected.

Any hints will be appreciated.

EDIT:

Just in case, somebody suggests using:

$(window).bind('beforeunload', function() { return 'Are you sure';} );

I’ve already tried it and it behaves the same way as using pure Javascript.

  • 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-25T20:22:21+00:00Added an answer on May 25, 2026 at 8:22 pm

    Ok, I’ve finally figured a solution, which is probably not the cleanest one – because I don’t know the exact cause of the problem – but it works. I’ve put my beforeunload function into jQuery’s load function so it is executed after DOM and other elements are loaded.

    $(window).load(function () {
      $(window).bind('beforeunload', function() { return 'Are you sure ?';} );
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am having a strange problem, i have a static class like this public
I'm having a strange problem and not sure how to troubleshoot it. I have
Here's an interesting problem: I have some jQuery that looks like this: $(document).ready(function() {
I'm having a strange problem. I have to use GetPostBackEventRefence to force a Postback,
I'm having a strange problem in Visual Studio 2008 where my Pending Checkins window
I'm having a strange problem here... I have an ASP.NET 3.5 application that has
I'm having a strange problem in that I have php inserting text into a
Im having a very strange problem, i have a complicated view that returns incorrect
I am having some strange problems loading content from another XHTML page via jQuery.
I'm having this strange problem with cloned elements(using .clone(true)) with draggable and resizable functionalities

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.