PrefaceDuring the development process, we sometimes encounter similar requirements, such as remembering the operations performed by users at the browser level. I have made a function before, which used a drag plug-in to display a report chart similar to a nine-square grid. Each graph can be displayed and hidden. If the user clicks the show or hide button, the browser will retain the last operation result when entering the system next time. The core part is to use js to operate cookies, and the specific business part is to trigger a click event on a graphic. If it is hidden, the div corresponding to the graphic will be deleted from the cookie. When it is displayed, the graphic div will be written into the cookie. This article only records some cookie operations. You can write specific business codes according to your actual situation. When are cookies used?
Here’s how1. Set cookie parameters: cname: cookie name, cvalue: cookie value, exdays: cookie expiration time function setCookie(cname,cvalue,exdays) { var d = new Date(); d.setTime(d.getTime()+(exdays*24*60*60*1000)); var expires = "expires="+d.toGMTString(); document.cookie = cname + "=" + cvalue + "; " + expires; } 2. Get cookies function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i].trim(); if (c.indexOf(name)==0) return c.substring(name.length,c.length); } return ""; } 3. Deleting cookies function delCookie(cname) { var exp = new Date(); exp.setTime(exp.getTime()-1); var cval = getCookie(cname); if(cval != null){ document.cookie = cname + "=" + cval + ";expires=" + exp.toGMTString(); } } I hope this article is helpful to you. If it is useful, remember to follow me and continue to output more content for you later. Reference: Cookie Operation SummarizeThis is the end of this article about how js uses cookies to remember user page operations. For more relevant js cookies to remember users content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to create your own image using Dockerfile
>>: MYSQL A question about using character functions to filter data
Anyone who has used the Linux system should know ...
Table of contents Preface Introduction to Bezier ...
<br />For an article on a content page, if t...
The effect of completing a menu bar through displ...
Table of contents Vue2.x Usage Global Registratio...
1. There are two ways to modify global variables ...
This article shares the simple process of install...
MySQL full text search Chinese solution Recently,...
This article shares the specific code of vue3 enc...
1. Log4j for log segmentation 1) Prepare three pa...
Before CSS3, gradient images could only be used a...
Table of contents 1. What is a calculated propert...
Download and installConfigure environment variabl...
The configuration method of MySQL 5.5.56 free ins...
Table of contents 1. Global Guard 1. Global front...