Click to return to the HTML Help home page    
Web Workshop  |  DHTML, HTML & CSS  |  HTML Help

Linking to a .chm from a Web page

Microsoft Corporation

Updated: May 12, 1999

If you've built help projects using HTML Help, you probably know that you can link to a Web page from a topic in a compiled help (.chm) file. This is a great way to give users access to updated material. But what if you want to link to a specific help topic in a .chm from a Web page? This can easily be done by defining a new window type in your help project, and using the showHelp method to call HTML Help and display the topic.

To link to a topic in a .chm file from a Web page

  1. Open a help project (.hhp) file in HTML Help Workshop, and then create a new window type. You can name it whatever you like. Keep in mind that you can customize the new window type in HTML Help Workshop. For example, you could create a standard tri-pane window that shows the Table of Contents and Index, or create a window type that shows only the help topic and nothing else.
  2. Save the project file and compile.
  3. For the link itself, you need to create a string that will be called by the showHelp method. Here is an example of what the entire string looks like:
    mk:@MSITStore:C:\Program Files\My
    Program\help\myhelp.chm::/mytopic.htm>mywindow
    
    The first part of the string uses the moniker protocol:
    >mk:@MSITStore:
    
    Next comes the path to the compiled help file location on the user's machine. Relative paths do not work. Use backslashes. For example:
    C:\Program
    Files\MyProgram\help\myhelp.chm
    
    After this path, add two colons and a forward slash:
    ::/
    
    Then you must add the file name of the HTML file you want to appear. If you need to specify a path within the CHM, be sure to use forward slashes for this path. If the file is in a subdirectory of the compiled CHM file, add that too:
    mytopic.htm
    
    or
    mysubdir/mytopic.htm
    
    Finally, you must add a ">" bracket and the the window type name:
    >mywindow
    
    Here is a sample Web page that shows one way of implementing the showHelp method:
    <HTML>
    <head><title>Test of HTML
    Help</title></head>
    <body>
    <script language="VBScript"
      EVENT="OnClick" FOR="link_1"><!--
    window.showHelp(
      "mk:@MSITStore:C:\Program Files\My
    Program\help\myhelp.chm::/mytopic.htm>mywindow")
    //--></script>
    <a name="link_1" HREF="#">Link to
    mytopic.htm</a>
    </body>
    </HTML>
    

    Although this example adequately demonstrates the functionality of the showHelp method, it has a shortcoming: each link requires its own script. That means if you have five links on a page, you also need to duplicate the script five times. To get around this, try passing the path as a variable as shown in the following example:

    <script language="VBScript">
    sub link_all(url)
        window.ShowHelp("mk:@MSITStore:"+url+">mywindow") 
    end sub
    </script>
    

    Use the following syntax for each link:

    <a href="#" onclick='link_all("C:\my documents\test\testproj1.chm::/file1.htm")'>file 1</a>
    <a href="#" onclick='link_all("C:\my documents\test\testproj1.chm::/file2.htm")'>file 2</a>
    
    Note You can also use a standard <A HREF> link to open an entire help file from a Web page. When a user clicks the link a dialog box will appear that gives them the option of saving the compiled help file to their hard disk or opening it from the directory where it's located. For example,
    <A HREF="file name.chm">Link
    text</a>.
    


Back to topBack to top

Did you find this material useful? Gripes? Compliments? Suggestions for other articles? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.

 

link to overview topic Tips and Tricks