How do I make JavaScript alerts?
How do I make JavaScript prompts?
How do I make JavaScript confirms?
How do I make JavaScript alerts? JavaScript alerts are annoying little pop-ups that most kids love (and most adults don't lol). There are several different versions listed here. You can place these scripts anywhere in the body tag.
- Alert on click:
<form ACTION=URI><input type="button"
value="click here"
onClick='alert("Your message here")'></form>
A prettier version:
<form ACTION=URI><input type="button" style="background:#9900ff" value="click here" onClick='alert("Your message here")'></form>
- Alert on mouseover:
<a href=""onMouseover="alert('write your message here')">Put your own words here</a>
Run your cursor over this link =)
- Alert upon entering page:
<SCRIPT language="JavaScript type="text/javascript"">alert("your message here")</SCRIPT>
- More than one alert upon entering page:
<script language="JavaScript type="text/javascript"">
<!-- start script
alert("Your message here");
alert("Your message here");
alert("Your message here");
// end script -->
</script>
- Alert upon leaving page:
<body onunload="alert('your message here');">
- Alert upon entering AND leaving page:
<body onload="alert('Your enter message here');"
onunload="alert('Your exit message here');">
- Alert upon entering page with time and date shown:
<script language="JavaScript" type="text/javascript">
<!-- Hide the JavaScript from older browsers
document.write("Having a great day?")
document.write("<BR>")
document.write("Today's date is ",Date())
// End hiding of script -->
</script>
- Alert upon leaving page showing time spent on your page:
This code gets pasted in your HEAD tag:
This code gets pasted into your BODY tag:
<body onUnLoad="WinOpen()" onLoad="getLogonTime()";>
How do I make JavaScript prompts? A JavaScript prompt is a popup window that asks for information from your visitor. Here are some examples of JavaScript prompts:
- The following code will display a greeting and your visitors name on your page if they type their name into the prompt screen. Add this code into your <Head> tag:
And add this code into your <body> tag where you want the prompt text to show up on your page:
- Here is a JavaScript prompt that asks for a password, and if the password is correct it will take your visitor to the password protected page. NEVER NEVER NEVER use this for anything important. It is just a fun script that is absolutely not foolproof in any way. Almost anyone on the net would be able to figure out how to get around this script LOL, put this script in the head tag:
<script language="JavaScript" type="text/javascript">
<!--hide
var password;
var pass1="yourpasswordhere";
password=prompt('Enter your password in order to view this page!',' ');
if (password==pass1)
alert('YAY you got it right! Click OK to enter!');
else
{
window.location="http://www.lissaexplains.com";
}
//-->
</script>
- Here is another version of a JavaScript prompt that can allow your visitor to change the background color of your Web site, on mouseover, if you use a solid color background:
<a href="" onMouseOver="var bg=prompt('What color would you like?');document.bgColor=bg">Put your cursor over this link to change background color!</a>
Because of my tables, this example won't work here, but you can see what the prompt looks like =)
Put your cursor over this link to change background color!
- Here's a JavaScript prompt that asks your visitor for their name, and welcomes them with an alert after they fill in their name:
<script language="javascript" type="text/javascript">
var name = prompt("Write your name below:","Write it here.");
alert("Welcome "+ name +" to my page!!!");
</script>
How do I make JavaScript confirms? A JavaScript confirm is an alert that asks your visitor to decide between 2 choices you offer them.
- This confirm warns your visitor to "Enter at your own risk" and if they press cancel, will be taken to another Web site:
<script language="javascript" type="text/javascript">
var stay=confirm("Enter at your own risk!! Press "ok" to enter, "cancel" to exit immediately!")
if (!stay)
window.location="http://www.lissaexplains.com"
</script>
Copyright 1997-2016 Lissa, All rights reserved