Using Cookies to set an alert in javascript -


i'm trying create script when user opens site or welcomed prompt , after alert welcome entered in prompt set cookie 1 minute problems i'm facing are:
1. alert not show up
2. cookie not set

function checkcookie() {     var username=getcookie("username");     if (username!=null && username!="") {         alert("welcome again "+ username);       }     else {         username=prompt("please input name:","");         if (username !=null && username!="") {             setcookie("username", username, 365);         }         else {             alert("error");         }     } } function setcookie (cname,cvalue,exdays) {     var d = new date();     d.settime (d.gettime()+ (10*1000));     var expires ="; expires= "+ d.togmtstring();     document.cookie = cname + "=" + cvalue + "; " + expires; +"; path /"; } function getcookie(cname) {     var name = cname + "=";     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);         }            if (c.indexof(name) == 0){             return c.substring(name.length, c.length);         }     }     return ""; } 

try replacing var expires ="; expires= "+ d.togmtstring(); var expires ="; expires= "+ d.toutcstring();

the expire time saved unix timestamp.

edit: need execute function checkcookie too. thought obvious.

https://jsfiddle.net/osgohu5b/


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -