https://github.com/patrickjs/angular-beforeunload
Angular.js service for onBeforeUnload
https://github.com/patrickjs/angular-beforeunload
Last synced: 20 days ago
JSON representation
Angular.js service for onBeforeUnload
- Host: GitHub
- URL: https://github.com/patrickjs/angular-beforeunload
- Owner: PatrickJS
- Created: 2013-09-26T07:19:16.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-12-04T18:45:54.000Z (about 12 years ago)
- Last Synced: 2025-05-02T22:48:59.948Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 130 KB
- Stars: 7
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# angular-beforeunload [](https://travis-ci.org/gdi2290/angular-beforeunload)
Confirm dialog pop up if they try and (or accidently click away from) the page.
You can download angular-beforeunload by:
* (prefered) Using bower and running `bower install angular-beforeunload --save`
* Using npm and running `npm install angular-beforeunload --save`
* Downloading it manually by clicking [here to download development unminified version](https://raw.github.com/gdi2290/angular-beforeunload/master/angular-beforeunload.js)
```javascript
angular.module('YOUR_APP', [
'angular-onbeforeunload'
])
.controller('MainCtrl', function(onBeforeUnload) {
// Bind a listener on your current $scope and save reference to it.
var onbeforeunload = $scope.$on('$locationChangeStart', BeforeUnload.init('TOP_MESSAGE', 'BOTTOM_MESSAGE'))
// In this controller the user will be prompted to
// confirm their choice before they change their location.
$scope.submitPage = function() {
// If you invoking your reference then your listener becomes null.
onbeforeunload();
};
});
```