
commit dc50e832589bda7bf5851f7ef7c05a83fb7b93e1 Author: Alexandre Allaire <alexandre.allaire@mail.mcgill.ca> Date: Thu Dec 6 14:49:39 2012 -0500 Do not set test cookie to determine if cookies are enabled. If navigator.cookieEnabled is undefined, the current code will fall back to setting a test cookie to determine if cookies are enabled. This may overwrite an already present cookie, and may cause trouble for people who wish to host the badge on their own websites. This drops support for older browsers such as IE <= 4 and Netscape <= 6 (each more than 10 years old). --- proxy/options.js | 23 ++++------------------- 1 files changed, 4 insertions(+), 19 deletions(-) diff --git a/proxy/options.js b/proxy/options.js index c10b189..665ab31 100644 --- a/proxy/options.js +++ b/proxy/options.js @@ -8,23 +8,8 @@ var COOKIE_LIFETIME = "Thu, 01 Jan 2020 00:00:00 GMT"; window.addEventListener("load", function () { - /* This checks if cookies are enabled in the browser. - document.cookie has special behavior, if cookies - are disabled it will not retain any values stored in it. */ - function cookies_enabled() { - /*Not supported in all browsers.*/ - if (navigator.cookieEnabled) { - return true; - } else if (navigator.cookieEnabled === undefined) { - document.cookie = "test"; - if (cookie_present("test")) - return true; - } - return false; - } - /* Checks for a cookie with name cookie */ - function cookie_present(cookie) { + function cookie_present() { var cookies = document.cookie.split(";"); for (i in cookies) { @@ -32,7 +17,7 @@ window.addEventListener("load", function () { while (name[0] === " ") name = name.substr(1); - if (cookie === name) + if (COOKIE_NAME === name) return true; } return false; @@ -43,7 +28,7 @@ window.addEventListener("load", function () { var setting = document.getElementById("setting"); var prefix = "<p>Your current setting is: "; - if (cookie_present(COOKIE_NAME)) { + if (cookie_present()) { setting.innerHTML = prefix + "use my browser as a proxy. " + "Click no below to change your setting.</p>"; } else { @@ -60,7 +45,7 @@ window.addEventListener("load", function () { document.cookie = COOKIE_NAME + "= ;path=/ ;expires=Thu, 01 Jan 1970 00:00:00 GMT"; } - if (cookies_enabled()) { + if (navigator.cookieEnabled) { var buttons = document.getElementById("buttons"); buttons.addEventListener("click", update_setting_text); document.getElementById("yes").addEventListener("click", set_cookie);