This article mainly introduces how JavaScript uses cookies to display a DIV prompt box only once. It involves JavaScript's cookie-based flag-based techniques for controlling the modification of page element styles, for more information about how to use cookie to display a DIV prompt box only once, see the example in this article. We will share this with you for your reference. The details are as follows:
The JavaScript cookie technology is used here to control the prompt DIV displayed only once on the webpage, that is, it is displayed when the user opens the webpage for the first time and automatically hidden for the second time, it improves the user experience and does not bother users. Using Cookies, we can do a lot of things to get started.
The running effect is as follows:
The Online Demo address is as follows:
Http://demo.jb51.net/js/2015/js-cookie-p-dlg-show-once-codes/
The Code is as follows:
Cookie, only display the DIV prompt box onceScript function cookiesave (n, v, mins, dn, path) {if (n) {if (! Mins) mins = 365*24*60; if (! Path) path = "/"; var date = new Date (); date. setTime (date. getTime () + (mins * 60*1000); var expires = "; expires =" + date. toGMTString (); if (dn) dn = "domain =" + dn + ";"; document. cookie = n + "=" + v + expires + ";" + dn + "path =" + path ;}} function cookieget (n) {var name = n + "="; var ca = document. cookie. split (';'); for (var I = 0; I
I hope this article will help you design JavaScript programs.