I have a javascript object which I need global to my angularjs application. When the application is about to be unloaded (due to a page refresh or some other scenario), I would like to persist the object to browser storage. I believe adding the object to $rootScope would fulfill the first requirement of making the object global, but writing the object to storage during the onbeforeunload event, would require access to the $rootScope variable. Is it possible to detect a page unload event in angularjs?
Detecting page unload in angularjs
14.8k Views Asked by user1491636 At
1
There are 1 best solutions below
Related Questions in ANGULARJS
- Angular Show All When No Filter Is Supplied
- Using pagination on a table in AngularJS
- State with different subviews
- Getting and passing MVC Model data to AngularJS controller
- Implementing prerender.io middleware in sails.js
- Token based authorization in nodejs/ExpressJs and Angular(Single Page Application)
- AngularJS, Google App Engine and URLrewrite
- send data from table to another page into forms
- How to write tests for classes with inheritance
- angularJS sending OPTIONS instead of POST
- Receiving POST from external application in AngularJS
- Metaprogramming AngularJS Filters
- Reload List after Closing Modal
- Why is my angularjs site not completely crawlable?
- Why is separation of JavaScript and HTML a good practice?
Related Questions in GLOBAL-VARIABLES
- How do you run a javascript outside of the localhost directory with requirejs?
- Use same Python variable in multiple if-statements
- Declaring global char array in C header file
- Add global string to checkedlistbox?
- How to Declare Global Array Variable in SAS?
- What will be the possible causes for the 1st code fragment to output differently than 2nd and 3rd?
- Unexpected performance with global variables
- Using ng-init to call controller functions and passing vars between controllers
- Defining Global Variables or passing variables through function in Matlab?
- Global List not updating when using multiprocessing in python
- Difference between static and global variables
- Javascript, using one single local object instead of many local variables
- How do I organize input global variables?
- c++ program crash when creating global instance of class whose constructor references a global variable
- Javascript - Calling A Variable From Outside Of If/Else Block Returns Undefined
Related Questions in ONBEFOREUNLOAD
- javascript beforeunload not modifying data
- jQuery beforeunload custom pop up window for leaving a page
- prevent onbeforeunload to close page in any case
- Using onbeforeunload to create a custom confirmation warning?
- Before Unload keeps firing
- window.onbeforeunload works when close tab, but doesn't work when close browser
- Redirection to specified URL not happening during beforeunload for chrome using document.location.href or window.location or window.location.href
- Ajax inside onbeforeunload is not working the first time
- How to define different messages when Navigation Away and Reloading page?
- Condition within beforeunload event not working?
- jQuery beforeunload and areYouSure jquery plugin
- setting onbeforeunload on IE11
- Why is this jQuery unload event being executed immediately after load?
- PHP update database on close window
- Javascript function without any code in it
Related Questions in PERSIST
- Spark RDD checkpoint on persisted/cached RDDs are performing the DAG twice
- Yesod: querying `persist` database with a custom primary key
- Java-Jpa-Hibernate Detached entity pases to persist on merge
- Persisting Hashes in Ruby
- Persisting java objects in oracle blob
- Duplicate Entries using one-To-Many through non updated Id (PrimaryKey)
- Hibernate unidirectional one-to-many: Persist parent from children
- playframework JPA.em().merge(this); SQLGrammarException
- EntityManager.persist() doesn't save to database
- How to persist arraylist objects via em.persist()?
- jpa em.persist insert previously deleted items
- Hibernate JPA: detached entity passed to persist
- Symfony add data to object on pre persist
- I'm using Spring MVC and JSON to do some tasks, and i've got this exception
- Hibernate - Setting a cascade persist just for one session
Related Questions in ROOTSCOPE
- $rootScope.$broadcast in factory cannot change a value in other $scope
- $q doesn't remove pending tasks in angular
- How to reset $rootScope?
- Where is rootScope values are stored? In cookie or local storage?
- Angularjs - multiple location.path() in the same $rootScope boolean
- AngularJS Factory $rootScope.$on Cleanup
- Difference between angular.element().scope().$root and angular.element().injector().get('$rootScope')
- What is $rootScope doing in this function?
- how to delete $rootScope variable in angularjs?
- I am understanding rootScope and how it works.
- How to compare against global variables in ng-switch
- Setting initial $rootScope defaults don't seem to work
- Angular $broadcast only updating after page refresh
- Not reflect my changes in `$rootScope` in angularjs
- Detecting page unload in angularjs
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
This should do it, but I also suggest avoiding
$rootScopeas global state is discouraged, and you might also wraplocalStoragein a service so that it can be injected and mocked for testing.