Name Writing PromptThis script will prompt the viewer for a name and then write the name on the Web page.Script CodeGrab a copy of the file below and place it in the same directory as the Web page on which you will use the script (if you wish to place the script file in a different directory you will need to make the necessary adjustments to the src attribute of the script tag that calls it).The code below should be placed between the <body> and </body> tags where you want the greeting to appear. ExampleA working sample of the script is shown below. Click the link to get the page with the prompt and greeting.OptionsYou can change the text of the prompt by opening the salert5.js file and editing the bold (strong) text on the following line of code: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. AccessibilityA default welcome message without a name is placed inside the <span></span> tags on the page for viewers with JavaScript off. If the script runs, it will override the default greeting and write the greeting with the name in that space instead.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. |