I'm trying to reload the page only when the cookie (userInfo) value includes pageCount=1.
This is my cookie value for 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 i am trying to achieve is that once the geoLocation is allowed, if the pageCount=1 then reload the page once. Currently the page is reloading regardless of what pageCount=.
Here is my 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 to find your location");
}
}
// Get 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 for JQuery solutions.
Thanks for your help