title: onbeforeunload not working - tried javascript and jquery
body: <p><strong>This is not a duplicate.</strong> I have read through several other Stack posts and have attempted various approaches at this (both pure javascript and jquery), including these:</p>
  
  <p><a href="https://stackoverflow.com/questions/22776544/why-is-jquery-onbeforeunload-not-working-in-chrome-and-firefox">Why is jQuery onbeforeunload not working in Chrome and Firefox?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2638975/prompting-and-preventing-user-from-navigating-away-closing-a-page">Prompting and preventing user from navigating away/closing a page</a></p>
  
  <p>I have implemented a bare-bones simple approach at prompting the user with a messagebox but it never works. Clicking the "go to google" link ought to prompt the box, but it doesn't. Here is my full code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;script&gt;
  
      window.onbeforeunload = confirmExit;
      function confirmExit()
      {
          return "You have attempted to leave this page.";
      }
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
      &lt;a href="https://www.google.com/"&gt;go to google&lt;/a&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I have also tried the jquery approach. I am using Chrome 47.0.2526.106 m. What am I doing wrong?</p>