Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use localStorage or globalStorage to store the data:</p> <pre><code>if(typeof localStorage['userName'] === "undefined") { // defining the localStorage variable localStorage.setItem('userName', 'taranfx'); } alert("Your user is: " + localStorage.getItem('userName')); </code></pre> <p>OR you can use cookies to store the value even after refresh of the page:</p> <p>Cookies can be created, read and erased by JavaScript. They are accessible through the property document.cookie. Though you can treat document.cookie as if it's a string, it isn't really, and you have only access to the name-value pairs.</p> <p>If I want to set a cookie for with a name-value pair 'ppkcookie1=testcookie' that expires in seven days from the moment I write this sentence, I do</p> <pre><code>document.cookie = 'ppkcookie1=testcookie; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/' </code></pre> <ol> <li>First the name-value pair ('ppkcookie1=testcookie')</li> <li>then a semicolon and a space</li> <li>then the expiry date in the correct format ('expires=Thu, 2 Aug 2001 20:47:11 UTC')</li> <li>again a semicolon and a space</li> <li>then the path (path=/)</li> </ol> <p>This is a very strict syntax, don't change it! </p> <p>Also, even though it looks like I'm writing this whole string to the string document.cookie, as soon as I read it out again I only see the name-value pair:</p> <pre><code>ppkcookie1=testcookie </code></pre> <p><a href="http://www.quirksmode.org/js/cookies.html" rel="nofollow">http://www.quirksmode.org/js/cookies.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload