I have a webpage. After I open it, I will pop up a notice or advertisement. Anyway, I want to pop a window.
If you don't click "don't remind me next time", it will still pop up for you next time!!!
Who, for example, and why did you hit him?
Implementation method: After the user clicks "no more pop-up", a value will be written, for example: bunchhuang = true. After the page is loaded, it will judge whether the value is true. If it is true, it will not pop up
In addition to cookies, you can use simpler Local storage To achieve this function.
What is localstorage
In HTML5, a new local storage feature is added. This feature is mainly used as local storage to solve the problem of insufficient cookie storage space (the storage space of each cookie in the cookie is 4K). The general browsers in local storage support 5m size, which is different in different browsers.
Advantages of local storage
1. Local storage extends the 4K limit of cookies
2. Local storage can directly store the first request data locally. This is equivalent to a 5m size database for front-end pages. Compared with cookie, it can save bandwidth, but this is only supported in higher version browsers
Limitations of local storage
1. The size of browsers is not uniform, and the local storage property is only supported in IE version above IE8
2. At present, all browsers will limit the value type of localstorage to string type, which requires some conversion for the common JSON object type
3. Localstorage is not readable in browser privacy mode
4. The essence of local storage is to read the string. If the storage content is too much, it will consume memory space and cause page change
5. Localstorage cannot be crawled by crawler
6. Local storage is permanent storage
Write and modify operations for localstorage
window.localStorage["name"] = "Bourbon";
window.localStorage.age = 18;
The above code writes the name, age and Sex fields in three different ways, and also gives the corresponding values: bourbon, 18, and male.
window.localStorage["name"] = "Bobi";
Modifying the value of a field can be directly overridden with the new value.
Reading of localstorage
You can also read their values in three different ways.
By the way, no matter what the type of storage string is, you can only store the result.
window.localStorage.num = 666;
console.log(typeof window.localStorage.num); // string
window.localStorage.bool = true;
console.log(typeof window.localStorage.bool); // string
Removal of localstorage
You can use the clear() method to clear all fields.
You can also use the removeitem() method to delete the specified field.