APOORVA KALMANI
APOORVA KALMANI

Reputation: 11

alert inside unload event listener is not working in IE 11 browser

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?

Upvotes: 0

Views: 46

Answers (0)

Related Questions