Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

FP: How to Create a Home Page Hot Key in FrontPage by Using JavaScript


View products that this article applies to.

Summary

This article illustrates how a key that is pressed when a user is viewing a Web page can be used to direct the browser to another location. The JavaScript example presented in this article associates the "H" key with a URL. When a user presses H, the browser navigates to that URL. You can use this procedure on a Web site as a "hot key" to return to the site home page.

NOTE: This article uses custom JavaScript that may not be available in all browsers. For more information about this topic, click Microsoft FrontPage Help on the Help menu, type compatibility in the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


More information

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

  1. Open a Web in FrontPage.
  2. Open the page where you want to insert the "hot key" feature.
  3. Switch to HTML view.
  4. 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>
    						
  5. 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.

↑ Back to the top


Keywords: KB288181, kbhowto, kbarchive, kbnosurvey

↑ Back to the top

Article Info
Article ID : 288181
Revision : 4
Created on : 10/26/2013
Published on : 10/26/2013
Exists online : False
Views : 225