Javascript - Prompt

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > ECMAScript - Grammar Standard

1 - About

Function Window.prompt

3 - Example

function setUserName() {
 
   var myName;
    if(!localStorage.getItem('name')) {
       myName = prompt('Please enter your name.');
       localStorage.setItem('name', myName);  
    } else {
       myName  = localStorage.getItem('name');
   }
 
   var myHeading = document.querySelector('p');
   myHeading.textContent = 'Hello  ' + myName;
 
}
 
setUserName();
 
var myHTML = document.querySelector('button');
myHTML.onclick = function() {
    localStorage.removeItem('name');
    setUserName();
}
<p>Hello comes here</p>
<button>Change user</button>

Advertising

4 - Documentation / Reference

web/javascript/es/prompt.txt · Last modified: 2019/02/16 17:40 by gerardnico