+ 5
Who will solve this issue ?
I was trying to store and retrieve cookies in code playground with browser object model but after all setup there was an uncaught security error. Error Message : _______________ failed to read the 'cookie' property from 'document': access is denied for this document.
2 odpowiedzi
+ 6
Do someone know about local storage instead of cookies ?
+ 3
CODE FOR COOKIES
____________________
function startup()
{
if(navigator.cookieEnabled = true)
checkCookie();
}
function checkCookie()
{
var userName = getCookie("username");
if(userName!="")
{
alert("Welcome again " + userName);
}
else
{
userName = prompt("Enter your name","");
if(userName != "" && userName != null)
setCookie("username",userName,"Sunday 8 November 2016 12:00:00")
}
}
function setCookie(cName,cValue,cExpDate)
{
document.cookie = cName + "=" + cValue + ";" + "expires=" + cExpDate + ";";
}
function getCookie(cName)
{
var cookieName = cName + "=";
var cookiArray = document.cookie.split(";");
for(var i=0;i<cookieArray.length;i++)
{
var everyCookieString = cookieArray[i];
while(everyCookieString.chatAt(0)==" ")
{
everyCookieString = everyCookieString.substring(1);
}
if(everyCookieString.indexof(cookieName)==0)
{
return everyCookieString.substring(cookieName.length,everyCookieString.length);
}
}
return "";
}