Well for the website I made a little script that when you load the site there is a prompt that asks for your name, and when you submit it, it displays a hello message in the header.
The problem is that when you go to the different pages of the website the script executes again and ask for the name again. For instance, you go from home to the contact section and when the contact section loads, the prompt appears again. I want that to execute once and display the information throughout the entire website. Here is the JS Code:
var nombre = sessionStorage.setItem[prompt("Bienvenido a Plantas All the Time, ingrese su nombre:")]
var login = sessionStorage.getItem(nombre);
if (nombre == "") {
prompt("Bienvenido a Plantas All The Time, ingrese su nombre:")
} else {
document.getElementById('usuario').innerHTML = "<h4> Hola, " + nombre + "</h4>";
}
Whenever I execute this the prompt appears I enter the name and it prints "undefined".
Aucun commentaire:
Enregistrer un commentaire