This is not a duplicate. I have read through several other Stack posts and have attempted various approaches at this (both pure javascript and jquery), including these:
Why is jQuery onbeforeunload not working in Chrome and Firefox?
Prompting and preventing user from navigating away/closing a page
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:
<html>
<head>
<script>
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "You have attempted to leave this page.";
}
</script>
</head>
<body>
<br /><br /><br /><br /><br />
<a href="https://www.google.com/">go to google</a>
</body>
</html>
I have also tried the jquery approach. I am using Chrome 47.0.2526.106 m. What am I doing wrong?