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.
NOTE: You may receive an error message if you copy the examples directly from this article and paste them into FrontPage. The angle brackets (< and >) may appear as escaped HTML code (< and >). To work around this behavior, paste the script into a blank Notepad document, and then copy it from Notepad before you paste it into FrontPage.
Code Sample
- Open a Web in FrontPage.
- Open the page where you want to insert the "hot key" feature.
- Switch to HTML view.
- Insert the following JavaScript code in the <HEAD></HEAD> section of the HTML page. (Change the destination HTTP address to the URL that you want to become the home page.)
<script language="JavaScript">
<!--
// define our "hotkeys", use "Character Map" for values.
var HotkeyLcase=104;
var HotkeyUcase=72;
// define our destination.
var destination="http://www.microsoft.com/";
// set up page to capture keypress events.
if (document.layers)
document.captureEvents(Event.KEYPRESS);
// the following function tests which key was pressed
// and redirects to our destination if the key is valid.
function backhome(e){
if (document.layers){
if ((e.which==HotkeyLcase) || (e.which==HotkeyUcase))
window.location=destination;
}
else if (document.all){
if ((event.keyCode==HotkeyLcase) || (event.keyCode==HotkeyUcase))
window.location=destination;
}
}
// point keypress events to our function
document.onkeypress=backhome;
//-->
</script>
-
When you preview the Web page in your browser and press H on your keyboard, your browser navigates to the page that you specified in the JavaScript.