0

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?

Community
  • 1
  • 1
HerrimanCoder
  • 6,835
  • 24
  • 78
  • 158
  • code you posted works for me in same version of Chrome, maybe something in settings?? – WhiteHat Jan 06 '16 at 14:42
  • I have the same version of Chrome than you (but on Mac) and it seems to work all right, but the dialog is prompted twice :-/ – fray88 Jan 06 '16 at 14:42
  • the above code only works for me if I click refresh. If I click another link on the page it doesn't provide the prompt. – daveomcd Jul 23 '16 at 20:36

0 Answers0