Opening an Alert Box in Javascript
alert() is a built-in Javascript method.
A little tricky here with the quotation marks (See IMPORTANT note below).
Put what you want the alert to display in single or double quotation marks.
Example in a script:
alert("Do Not Leave My Site!");
Example in a link:
<a href="http://google.com" onClick="alert('You are going to Google!');return true">Google</a>
When passing a varible to alert(), use no quotation marks at all.
var ko = "Google me.";
alert(ko);
Quotation marks around
ko would display the word
ko rather than the value of the variable
ko.
IMPORTANT:
-In a script: Backslash out quotes in your display text or make them opposite the containing marks. Examples:
alert("He said \"hey man\"");
alert('He said \'hey man\'');
alert("He said 'hey man'");
alert('He said "hey man"');
alert("Don't leave my site");
alert('Don\'t leave my site');
-In a link: Backslash out quotes in display text. Example:
<a href="#" onClick="alert('Doesn\'t go to Google');return true">Google</a>
You can look at that as being complicated or you can see it as flexible.
Copy and Paste Javascript (two ways to use):
In a link:
<a href="http://google.com" onClick="alert('You are going to Google!');return true">Google</a>
In a script:
<script type=text/javascript>
<!--
alert("Don't Leave My Site!");
-->
</script>
Note: When using in a link, the "return true" means go to the link that is being clicked on. "return false" stops the browser from going to the link.
Alert Box - See in Action (new window)