javascript - I want clear the cookies of a page when loading from another page but not when the same page is reloaded -


i building new website , have created page has array store in cookies , clearing array using

$.removecookie("checkboxvalues");

i running function when document gets ready. when coming page page using link want clear cookies , yes happening. problem if load same page (using f5 or ctrl + r) cookies gets cleared , don't want loose cookies. kind of appreciated. thanks.

you can try 1 of below:

the easiest way can think of achieve put time-stamp in query string of redirect , read in javascript. set cookie time stamp , detect whether exists tell whether page being reloaded (has been loaded query-string before).

code :

store cookie first time visits page. on refresh check if cookie exists , if does, alert.

function checkreload() {   if(document.cookie.indexof('yourcookie')==-1) {     // cookie doesn't exist, create   }   else {     // not first visit, alert     alert('you refreshed!');   } } 

and in body tag:

<body onload="checkreload()"> 

one more :

first step check sessionstorage pre-defined value , if exists alert user:

if (sessionstorage.getitem("is_reloaded")) alert('reloaded!'); 

second step set sessionstorage value (for example true):

sessionstorage.setitem("is_reloaded", true); 

session values kept until page closed work if page reloaded in new tab site.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -