Quantcast
Channel: User Brett Merrifield - Stack Overflow
Viewing all articles
Browse latest Browse all 37

Answer by Brett Merrifield for Meteor, ReactJS, MongoDB: Do something when user leaves page

$
0
0

Maybe window.onbeforeunload will be helpful here. It executes Javascript when the user leaves the page.

Meteor:

Meteor.startup(function(){    $(window).bind('beforeunload', function() {        closingWindow();    });});closingWindow = function(){    ...}

React:

componentDidMount() {  window.addEventListener('beforeunload', this.handleLeavePage);}componentWillUnmount() {  window.removeEventListener('beforeunload', this.handleLeavePage);}handleLeavePage() {  ...}

Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>