This article contains sample JavaScript code that displays a random quote
when the HTML document is loaded.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
For this JavaScript code to function, you must type it manually in the
HTML code. The FrontPage user interface does not provide a means to insert
JavaScript code between the closing <\HEAD> tag and the opening <BODY> tag.
Editing the HTML Code
- To view the HTML code, start FrontPage, Change to the page view, and
click the HTML tab.
- Insert the following JavaScript code between the </HEAD> tag and
the <BODY> tag in the HTML document:
<SCRIPT LANGUAGE="JScript">
<!--
function DisplayQuote() {
// Build an array of quotes
var quote = new Array(20)
quote[0] = "Quote example 1"
quote[1] = "Quote example 2"
quote[2] = "Quote example 3"
quote[3] = "Quote example 4"
quote[4] = "Quote example 5"
quote[5] = "Quote example 6"
quote[6] = "Quote example 7"
quote[7] = "Quote example 8"
quote[8] = "Quote example 9"
quote[9] = "Quote example 10"
quote[10] = "Quote example 11"
quote[11] = "Quote example 12"
quote[12] = "Quote example 13"
quote[13] = "Quote example 14"
quote[14] = "Quote example 15"
quote[15] = "Quote example 16"
quote[16] = "Quote example 17"
quote[17] = "Quote example 18"
quote[18] = "Quote example 19"
quote[19] = "Quote example 20"
// Determine today's date and pick a quote
// based on the second.
var now = new Date()
var sec = now.getSeconds()
alert("Today's Quote:\r" + quote[sec % 20])
}
//-->
</SCRIPT>
- Add a OnLoad directive to the BODY tag to run the Jscript.
For example, the <BODY> tag should appear as follows:
<BODY OnLoad="DisplayQuote()">