0

Below is the HTML code snippet where I am trying to display an alert during unload event. But I am not able to see the alert.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />

    <title>IE App</title>
  </head>
  <body>
    <h3>I am IE Compatible app.</h3>
    <div id="demo"></div>

    <script>
      document.getElementById("demo").innerHTML = "Javascript is enabled";
      window.addEventListener('unload', function(event) {
       alert('Unload event from IE Modal');
      });
    </script>
  </body>
</html>

I can see from browser settings JavaScript pop ups are enabled. In IE browser console, I checked if alert works, it is working. I tried adding alert outside the unload event listener. I can see the alert pop up. I tried adding console.log() instead of alert, I can see the console logs. But the problem is only with alert inside unload event which is not displaying.

Can you please help me to know where I am going wrong and why alert inside unload event is not displaying?

  • 2
    Does it work in any other browser? – Konrad Mar 13 '23 at 17:26
  • 1
    You can't show an alert in an `unload` event, so this won't work in any browser, not just IE. More info here: https://stackoverflow.com/a/68637899/519413 – Rory McCrossan Mar 13 '23 at 17:28
  • 2
    Given that IE is now officially deprecated and MS is silently uninstalling it from desktop systems, we no longer (finally) have to worry about things not working in IE that work everywhere else. With that said, the unload event is a bit different than other events and you are limited as to what you can do there. – Scott Marcus Mar 13 '23 at 17:40

0 Answers0