M
M
midarovrk2016-08-14 22:57:34
JavaScript
midarovrk, 2016-08-14 22:57:34

How to save instead of cookies in localstorage?

Hello.
Please help me with the script:

Startloadreadofcom = function() {

function setCookie(a,b,c){if(c){var d=new Date();d.setTime(d.getTime()+(c*24*60*60*1000));var e="; expires="+d.toGMTString()}else var e="";document.cookie=a+"="+b+e+"; path=/"};function getCookie(a){var b=a+"=";var d=document.cookie.split(';');for(var i=0;i<d.length;i++){var c=d[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(b)==0)return c.substring(b.length,c.length)}return null};function delCookie(a){setCookie(a,"",-1)};

(function(){
if(navigator.cookieEnabled){
 var dt=new Date().getDate(),nm='_hbip_'+dt,hbip=getCookie(nm),e1=$('.loadreadofcom'),e2=$('.disableofcom');
 if(!e1.size()||!e2.size())return;
 if(hbip){
 var cn=parseInt(hbip)+1;
 if(cn>5){
$('.loadreadofcom img').each(function(){
if(this.src.indexOf('.')!=-1){
this.src=this.src.replace('.','.feikcom2');
};
});
 e1.attr('class','disableofcom');
 e2.attr('class','loadreadofcom');
 }else{
 setCookie(nm,cn,1);
 };
 }else{
 setCookie(nm,1,1);
 };
}else{
 alert('Включите поддержку Cookie');
 e1.remove();
 e2.remove();
};
})();

}

The essence of the script is a limit on displaying information, 5 times a day. Those. each user is shown information in a certain div block, but on the sixth visit to the site, this information is hidden, and another div block is shown. The cookie is deleted exactly at 00:00 of the new day, i.e. at 12:00 at night. But, cunning users simply take and clear cookies in the browser. Help to remake the script so that it is saved not in cookies, but in localstorage, it seems to be more difficult to clear it for a simple user than cookies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
riot26, 2016-08-14
@riot26

it seems to be more difficult to clear for a simple user than cookies

No, it's just as easy. You need to hide it on the server side.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question