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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:56:54+00:00 2026-06-11T05:56:54+00:00

This code runs fine on Firefox, but I can’t make the unload event work

  • 0

This code runs fine on Firefox, but I can’t make the unload event work on Chrome anymore. Did Chrome stop supporting the unload event?

This is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>

<script type="text/javascript" src="../jquery/jquery.js"></script>

<script type="text/javascript">

    function pageHidden(evt) { alert("Are you sure 1?"); } //WORKS ON FIREFOX BUT NOT IN CHROME
    window.addEventListener("pagehide", pageHidden, false);

    window.onunload = function () { alert("Are you sure 2?"); } //TRIGGERS ON LOAD NOT ON UNLOAD

    $(window).unload(function () { //WORKS ON FIREFOX BUT NOT IN CHROME
        alert("Are you sure 3?");
    });

</script>
</head>

<body>
TEST WEBSITE
<a href="http://www.iamawesome.com">external link</a>
</body> 
</html>

How can I get the unload event to work in Chrome?

Thanks!


ANSWER:
Don’t test the unload event with alerts 😉

  • 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-11T05:56:56+00:00Added an answer on June 11, 2026 at 5:56 am
    window.onunload = alert("Are you sure 2?");
    

    This is incorrect. You are setting onunload to the result of alert, you need to set it to a function:

    window.onunload = function(){
        alert("Are you sure?");
    }
    

    If you want to use jQuery, this will work in all browsers.

    $(window).unload(function () {
         alert("Are you sure?");
    });
    

    NOTE: It might seem like it’s not working in Chrome, but it is. That’s because Chrome blocks alerts in the onunload event.

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

Sidebar

Related Questions

Having some trouble w/ IE7. IE8, Chrome, Firefox all work fine, but IE7 won't
I have this code which runs fine in Python 2.5 but not in 2.7:
This code runs fine but the for statement by the meant to read back
Please check this code out it compiles and runs absolutely fine.. The question is
This is my code below. The program runs fine. I don't get any exceptions.
I have this code that runs but never stops. class A { public static
This code compiles, and runs successfully locally, but not on another server. Both machines
* SOLVED * Answer is in separate post below This code runs fine in
I'm trying to catch [ENTER] in a Microsoft TreeView-control. this code runs fine on
Imagine this small code $(document).ready(function() { $(#loadingDiv).load(sub/__window_div.php); }) It runs okay in Chrome, Firefox,

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.