How JavaScript creates a Welcome cookie
Editor to share with you how JavaScript creates a welcome cookie. I hope you will get something after reading this article. Let's discuss it together.
Create a welcome cookie function setCookie (cname, cvalue, exdays) {var d = new Date (); d.setTime (d.getTime () + (exdays*24*60*60*1000)); var expires= "expires=" + d.toGMTString (); [xss_clean] = cname + "=" + cvalue + ";" + expires; / * [xss_clean] = "username=John Doe Expires=Sun, 31 Dec 2017 12:00:00 UTC "; this function sets cookie by adding the cookie name, cookie value, and expired string. * /} function getCookie (cname) {var name = cname + "="; var ca = [xss_clean] .split (';'); for (var I = 0; I < ca.length; iTunes +) {var c = ca.trim (); if (c.indexOf (name) = = 0) {return c.substring (name.length, c.length);} return "" }} / / check whether cookie already exists, that is, check whether the page has visited function checkCookie () {var user = getCookie ('username'); if (user! = ") {alert (" Welcome "+ user +" visit again ");} else {user = prompt (" Please enter your name: ",") / / return value if the user clicks the cancel button in the prompt box, it returns null. If the user clicks the confirm button, the text currently displayed in the input field is returned. If (user! = "" & user! = null) {setCookie ("username", user, 30); / / the name of the cookie (cname), the value of the cookie (cvalue), and the number of days to know that the cookie expires (exdays). }}}