我在条款和条件.html上接受条款和条件(点击复选框)后,使用angularJs将任何用户重定向到request.html。 $ cookies功能适用于除IE以外的所有其他浏览器。对于IE,行为很奇怪。
第一次,portalApp.run函数中的警报显示“是”,但是第二次我看到第二个警告显示“未定义”,因为控件转到其他位置并且页面被重定向到“/”
我在第二个警报中看到未定义的原因可能是因为在IE中再次调用'/'url但这次没有调用saveData()函数。但是,我不明白为什么在IE中对'/'进行第二次调用而不是其他浏览器?
requestForm.jsp
<form name="formName" style="margin-top:10px;" method = "post">
<input type="submit" ng-model="butn" ng-click="saveData()">
</form>
myController.js
var portalApp=angular.module('portalApp',['ngRoute','ngCookies','ngSanitize']);
portalApp.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: '/termsandconditions.html',
controller: 'ackController'
})
.when('/request', {
templateUrl: '/request.html',
controller: 'reqController'
})
.otherwise({
redirectTo: '/'
});
});
portalApp.run(function($rootScope, $location, $cookies) {
$rootScope.$on('$locationChangeStart', function(ev, next, current) {
//checking url on location change start
if($location.path().indexOf('/request') == '0'){
var msg = $cookies.hasReadTerms;
alert(msg); // Alert to show cookie content
//checking cookies while accesing unlock request page
if(msg == 'yes'){
//user can access request page
} else {
//redirecting user to entry page
$location.path('/');
}
}
});
});
portalApp.controller('ackController', function($scope,$rootScope,$location,$cookies){
$scope.saveData = function(){
//setting cookies for user acknowledgement
$cookies.hasReadTerms = 'yes';
$location.path('/request');
}
});
portalApp.controller('reqController', function($scope,$rootScope,$location,$cookies){
// do something
}