Home Web Front-end JS Tutorial JS Add Cookie, Get Cookie Value, Delete Cookie, Detailed Examples_Javascript Skills

JS Add Cookie, Get Cookie Value, Delete Cookie, Detailed Examples_Javascript Skills

May 16, 2016 pm 04:34 PM
cookie

Cookies are a very practical function that can determine a certain status and are highly used in projects

Copy code The code is as follows:

Function setCookie(name,value)

var Days = 30;
        var exp = new Date();  
          exp.setTime(exp.getTime() Days*24*60*60*1000);
document.cookie = name "=" escape (value) ";expires=" exp.toGMTString();
        var strsec = getsec(time);  
        var exp = new Date();  
          exp.setTime(exp.getTime() strsec*1);
document.cookie = name "=" escape (value) ";expires=" exp.toGMTString();
}  
//Read cookies
Function getCookie(name)

var arr,reg=new RegExp("(^| )" name "=([^;]*)(;|$)");
If(arr=document.cookie.match(reg))
Return (unescape(arr[2]));
            else  
                 return null;                               }  
//Delete cookies
Function delCookie(name)

        var exp = new Date();  
          exp.setTime(exp.getTime() - 1);
        var cval=getCookie(name);  
If(cval!=null)
                 document.cookie= name "=" cval ";expires=" exp.toGMTString();
}  

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Where are the cookies on your computer? Where are the cookies on your computer? Dec 22, 2023 pm 03:46 PM

Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

Where are cookies stored? Where are cookies stored? Dec 20, 2023 pm 03:07 PM

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.

Where are the mobile cookies? Where are the mobile cookies? Dec 22, 2023 pm 03:40 PM

Cookies on the mobile phone are stored in the browser application of the mobile device: 1. On iOS devices, Cookies are stored in Settings -> Safari -> Advanced -> Website Data of the Safari browser; 2. On Android devices, Cookies Stored in Settings -> Site settings -> Cookies of Chrome browser, etc.

How to find cookies in your browser How to find cookies in your browser Jan 19, 2024 am 09:46 AM

In our daily use of computers and the Internet, we are often exposed to cookies. A cookie is a small text file that saves records of our visits to the website, preferences and other information. This information may be used by the website to better serve us. But sometimes, we need to find cookie information to find the content we want. So how do we find cookies in the browser? First, we need to understand where the cookie exists. in browser

Detailed explanation of where browser cookies are stored Detailed explanation of where browser cookies are stored Jan 19, 2024 am 09:15 AM

With the popularity of the Internet, we use browsers to surf the Internet have become a way of life. In the daily use of browsers, we often encounter situations where we need to enter account passwords, such as online shopping, social networking, emails, etc. This information needs to be recorded by the browser so that it does not need to be entered again the next time you visit. This is when cookies come in handy. What are cookies? Cookie refers to a small data file sent by the server to the user's browser and stored locally. It contains user behavior of some websites.

Frequently Asked Questions and Solutions about Cookie Settings Frequently Asked Questions and Solutions about Cookie Settings Jan 19, 2024 am 09:08 AM

Common problems and solutions for cookie settings, specific code examples are required. With the development of the Internet, cookies, as one of the most common conventional technologies, have been widely used in websites and applications. Cookie, simply put, is a data file stored on the user's computer that can be used to store the user's information on the website, including login name, shopping cart contents, website preferences, etc. Cookies are an essential tool for developers, but at the same time, cookie settings are often encountered

The secret of cookie storage location: Do you know it? The secret of cookie storage location: Do you know it? Jan 19, 2024 am 09:47 AM

With the development of the Internet, we use browsers more and more frequently in our daily lives. When visiting a website, you often need to perform operations such as account login or browsing history. The implementation of these operations is inseparable from the cookie technology in the HTTP protocol. However, many people do not understand where and how cookies are stored. This article will reveal where and how cookies are stored, and provide specific code examples. 1. The storage location of cookies in the client (browser)

Where are cookies stored? Decrypt the data exchange mechanism behind the website Where are cookies stored? Decrypt the data exchange mechanism behind the website Jan 06, 2024 pm 10:57 PM

A cookie is a small text file stored on the user's computer and used by the web server to store data on the user's browser. The function of cookies is to store and transfer information when users visit the website to personalize the website and track users. First, let's understand where cookies are stored. Cookies can be stored in different locations in the user's browser. Among them, the most common ones are stored on the user's local file system, that is, in a specific folder on the hard disk. Cookies like this

See all articles