-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
totally redid cookies test. thx @tauren. fixes 191
- Loading branch information
Showing
1 changed file
with
13 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,15 @@ | ||
|
||
// cookies? | ||
// both delicious and useful. | ||
// by tauren | ||
// https://github.com/Modernizr/Modernizr/issues/191 | ||
|
||
Modernizr.addTest('cookies', function () { | ||
// Quick test if browser has cookieEnabled host property | ||
if (navigator.cookieEnabled) return true; | ||
// 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; | ||
}); | ||
|
||
(function(){ | ||
|
||
// FIXME: we could do this with less code. | ||
function createCookie(name,value) { | ||
document.cookie = name+"="+value+"; path=/"; | ||
} | ||
|
||
function readCookie(name) { | ||
var nameEQ = name + "="; | ||
var ca = document.cookie.split(';'); | ||
for(var i=0;i < ca.length;i++) { | ||
var c = ca[i]; | ||
while (c.charAt(0)==' ') c = c.substring(1,c.length); | ||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); | ||
} | ||
return null; | ||
} | ||
|
||
function eraseCookie(name) { | ||
createCookie(name,"",-1); | ||
} | ||
|
||
|
||
var random = '' + Math.round(Math.random() * 1e8); | ||
createCookie('Modernizr', random); | ||
Modernizr.cookies = readCookie('Modernizr') == random; | ||
eraseCookie('Modernizr'); | ||
|
||
})(); |