Ionic 1.3 close ionicModal on state back event


Is there a way to listen state back (on android -> back button, on ios -> swipe left) event on ionic as mobile web (not in a cordova app) ?

I want to check if an ionicModal shown. If so; close this modal and prevent to state change?

$ionicModal handles all this mess within a cordova app but I cannot find any solution while using it as mobile web application.

Could you please help?

The solution;

.directive('modalHide', function () {
    return {
        restrict: 'A',
        scope: true,
        link: function (scope, element, attrs) {
            var _modal,

            scope.$parent.$on('modal.shown', function (e, modal) {
                _modal = modal;

                _dereg = scope.$on('$stateChangeStart', function () {
      "show", scope.$$listeners.$stateChangeStart)

            scope.$parent.$on('modal.hidden', function (e, modal) {
                _dereg && _dereg();
      "hide", scope.$$listeners.$stateChangeStart)