The code below should be placed between the <body> and </body> tags where you want the greeting to appear.
var yourname = prompt('Please enter your name:','');
You can change the default name option (displays a name for the viewer if nothing is entered in the prompt) by editing the bold (strong) text on the following line of code:
yourname="Dude"; //sets a default name if nothing is entered
You can change the greeting text by editing the bold (strong) text on the following line of code. Be careful with the +greet_whom+ part of the line, as that is what places the viewer's name into the greeting.
greet.innerHTML = "Hello, "+greet_whom+"! Welcome to My Page!";
If you need to use single or double quotation marks within the prompt text or greeting, you should write them with a backslash before them (i.e. \" and \') in order to avoid JavaScript errors.
There are other ways to obtain accessibility as well such as using server-side scripts to get the name and write it on the page. The name could be remembered for the viewer if a cookie or login is used.
It should be noted that this script can be quite irritating and probably should be avoided by professional sites unless absolutely necessary.