/
cookies.js
37 lines (35 loc) · 1.13 KB
/
cookies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*!
{
"name": "Cookies",
"property": "cookies",
"tags": ["storage"],
"authors": ["tauren"]
}
!*/
/* DOC
Detects whether cookie support is enabled.
*/
define(['Modernizr'], function(Modernizr) {
// https://github.com/Modernizr/Modernizr/issues/191
Modernizr.addTest('cookies', function() {
// navigator.cookieEnabled cannot detect custom or nuanced cookie blocking
// configurations. For example, when blocking cookies via the Advanced
// Privacy Settings in IE9, it always returns true. And there have been
// issues in the past with site-specific exceptions.
// Don't rely on it.
// try..catch because some in situations `document.cookie` is exposed but throws a
// SecurityError if you try to access it; e.g. documents created from data URIs
// or in sandboxed iframes (depending on flags/context)
try {
// Create cookie
document.cookie = 'cookietest=1';
var ret = document.cookie.indexOf('cookietest=') !== -1;
// Delete cookie
document.cookie = 'cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT';
return ret;
}
catch (e) {
return false;
}
});
});