我最近决定开始尝试使一个网站符合欧盟cookie法律。我使用AngularJS作为我的前端框架。我一直在看这些jquery插件:
https://silktide.com/tools/cookie-consent/http://cookiesdirective.com/然而,如果可能的话,我更愿意使用角优先解决方案。有人知道任何角指令,将能够处理这个吗?
很简单。
angular.module('consent', ['ngCookies'])
.directive('consent', function ($cookies) {
return {
scope: {},
template:
'<div style="position: relative; z-index: 1000">' +
'<div style="background: #ccc; position: fixed; bottom: 0; left: 0; right: 0" ng-hide="consent()">' +
' <a href="" ng-click="consent(true)">I'm cookie consent</a>' +
'</div>' +
'</div>',
controller: function ($scope) {
var _consent = $cookies.get('consent');
$scope.consent = function (consent) {
if (consent === undefined) {
return _consent;
} else if (consent) {
$cookies.put('consent', true);
_consent = true;
}
};
}
};
});
为品味添加样式和动画
AngularJS provides the cookie API
查看链接AngularJS Cookie API
这是你将如何使用它
angular.module('cookiesExample', ['ngCookies'])
.controller('ExampleController', ['$cookies', function($cookies) {
// Retrieving a cookie
var favoriteCookie = $cookies.get('myFavorite');
// Setting a cookie
$cookies.put('myFavorite', 'oatmeal');
}]);