title: How to cancel unload event of an Iframe using Javascript
body: <p>I am trying to catch unload event of an Iframe, and prevent navigation, using the following code:</p>
  <pre><code>&lt;iframe
        onLoad={() =&gt; {
          iframeEl.current.contentWindow.addEventListener('beforeunload', (e) =&gt; {
            e.preventDefault();
            return false;
          });
        }}
  ...
  </code></pre>
  <p>But it keeps navigating to the undesired destination.
  What is the correct way of stopping it?</p>