I have some problems in my code. My web application is running on AngularJs 1.5. I have got an internet shop with a shopping cart. The problem is that data which should be saved in sessionStorage and restored after updating the browser is properly working on desktop browsers, but totally not working on iOS (tested Chrome and Safari). Android (Chrome) is working properly, too. While inspecting code in MacOS Safari from iPhone, the console is not throwing any errors. Here is the code:
(function(angular, loc) {
var app = angular.module('myModule', ['ui.bootstrap','ui.mask'])
app.run(function($rootScope) {
window.onbeforeunload = function(event) {
$rootScope.$broadcast('savestate');
};
});
app.factory('basket', ['$rootScope', function($rootScope) {
var basketData = {
content: []
};
function saveState() {
sessionStorage.basket = angular.toJson(basketData.content);
}
function restoreState() {
basketData.content = angular.fromJson(sessionStorage.basket);
}
$rootScope.$on("savestate", saveState);
if (sessionStorage.basket) restoreState();
return basketData;
}]);
...
})(angular, window.location);