Getting cookie value from cookie string javascript -


i'm trying reload page when cookie (userinfo) value includes pagecount=1.

this cookie value userinfo:

lastbranchvisitedname=no branch set&mostrecentbranchid=&pagecount=4&lastpageurl=/personal/life-health/over-50s-insurance/&allocatedbranchid=70&allocatedbranchtelephone=01993 894 700&allocatedbranchname=motor direct&locationlatitude=51.8969248&locationlongitude=-2.0758525999999997&lastpagedatetime=28/03/2017 14:37:26 

what trying achieve once geolocation allowed, if pagecount=1 reload page once. page reloading regardless of pagecount=.

here current javascript:

// hide / show notification depending on cookie window.onload = function () {  if (setcookievalue("geopopupcompleted") == undefined) {      if (navigator.geolocation) {         navigator.geolocation.getcurrentposition(setposition);      } else {         alert("unfortunately we're unable find location");     }  }  // page count var pagecount = getcookie("pagecount"); function getcookie(c_name) {     if (document.cookie.length > 0) {         c_start = document.cookie.indexof(c_name + "=");         if (c_start != -1) {             c_start = c_start + c_name.length + 1;             c_end = document.cookie.indexof(";", c_start);             if (c_end == -1) c_end = document.cookie.length;             return unescape(document.cookie.substring(c_start, c_end));         }     }     return ""; }  function setposition(position) {     setcookievalue("locationlongitude", position.coords.longitude);     setcookievalue("locationlatitude", position.coords.latitude);     setcookievalue("geopopupcompleted", true);      if (pagecount) {         (function () {             if (window.localstorage) {                 if (!localstorage.getitem("firstload")) {                     localstorage["firstload"] = true;                     window.location.reload();                 }                 else                     localstorage.removeitem("firstload");             }         })();    } } }  // geo cookie settings function setcookievalue(cookiename, cookievalue) {     var cookieexpiredate = "expires=sun, 31 dec 4017 12:00:00 utc; path=/";     document.cookie = cookiename + "=" + cookievalue + "; " + cookieexpiredate; } 

not looking jquery solutions.

thanks help

the following code worked me... hope helps else.

// hide / show notification depending on cookie window.onload = function () {  if (setcookievalue("geopopupcompleted") == undefined) {      if (navigator.geolocation) {         navigator.geolocation.getcurrentposition(setposition);      } else {         alert("unfortunately we're unable find location");     }  }  function setposition(position) {     setcookievalue("locationlongitude", position.coords.longitude);     setcookievalue("locationlatitude", position.coords.latitude);     setcookievalue("geopopupcompleted", true);      // page count     var pagecount = getcookie("pagecount");     function getcookie(c_name) {         if (document.cookie.length > 0) {             c_start = document.cookie.indexof(c_name + "=1");             if (c_start != -1) {                 c_start = c_start + c_name.length + 1;                 c_end = document.cookie.indexof(";", c_start);                 if (c_end == -1) c_end = document.cookie.length;                 return unescape(document.cookie.substring(c_start, c_end));             }         }         return "";     }      // reload page once     if (pagecount) {         (function () {             if (window.localstorage) {                 if (!localstorage.getitem("firstload")) {                     localstorage["firstload"] = true;                     window.location.reload();                 }                 else                     localstorage.removeitem("firstload");             }         })();     } } }  // geo cookie settings function setcookievalue(cookiename, cookievalue) { var cookieexpiredate = "expires=sun, 31 dec 4017 12:00:00 utc; path=/"; document.cookie = cookiename + "=" + cookievalue + "; " + cookieexpiredate; } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -