# Detecting when a user has moved off a view?

**URL:** <https://forum.ionicframework.com/t/detecting-when-a-user-has-moved-off-a-view/14789>\
**Category:** ionic-v1\
**Created:** [December 28, 2014, 7:12am UTC](https://forum.ionicframework.com/t/detecting-when-a-user-has-moved-off-a-view/14789 "2014-12-28T07:12:34Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [December 29, 2014, 10:37pm UTC](https://forum.ionicframework.com/t/detecting-when-a-user-has-moved-off-a-view/14789/4 "2014-12-29T22:37:38Z")

</div>

It seems to work fine for me

> **[Tabs And Navigation: Nightly](https://codepen.io/mhartington/pen/emdozV)**
>
> Demo showing how each tab has its own history stack. Navigating between each tab remembers the correct back and forward views that were visited. Forke...

```auto
  $scope.$on('$ionicView.beforeLeave', function(){
    alert("Before Leaving");
  });

  $scope.$on('$ionicView.afterLeave', function(){
    alert("After Leaving");
  });

```

---

_[View the full topic](https://forum.ionicframework.com/t/detecting-when-a-user-has-moved-off-a-view/14789)._
