user3764730
user3764730

Reputation: 1

How to capture the browser refresh in a backbone single page architecture

I have created a single page app using backbone. What I want to do is - when the user clicks F5 or hits on the browser refresh I want to capture that event and provide a JS alert to the user asking are you sure you want to refresh. Is there a way to do this using backbone

Upvotes: 0

Views: 170

Answers (1)

Reactgular
Reactgular

Reputation: 54761

There is no way to tell the difference between the user leaving a page or refreshing, but you can prompt a message to abort the activity.

<script type="text/javascript">
    window.onbeforeunload = function() {
        return "Are you sure you want to leave or refresh?";
    }
</script>

Upvotes: 2

Related Questions