Zum Inhalt

HTMLHelp

Open CHM topic by JavaScript using Internet Explorer

Is there a way to open CHM help file to a specific topic page via JavaScript?

The short story - use full path when looking inside a ITS (CHM) file. Relative path specifications including topic specification within the CHM do not work according to my tests. It only works for the CHM help file itself. A series of security fixes years ago has reduced HTMLHelp to functioning as local help only.

HTML Help 1.x does not have the capability of delivering compressed help over http. You can point to a .chm on the user's local drive, and you can link to a .chm for download, but that's as far as it goes.

The ability to look inside an ITS (CHM) file is something unique to Microsoft Internet Explorer only and Internet Explorer (NOT Microsoft Edge browser) could load a locally path like:

ms-its:D:\_temp\CHM-example.chm::/garden/garden.htm

Internet Explorer - open topic from CHM help file

The prefix ms-its is a pluggable protocol from earlier days that follows old standards set up by the World Wide Web Consortium (W3C). The ms-its protocol works with Microsoft Internet Explorer 4.0 or later, but is not supported in all browsers.

So, for test case only I have a test.htm file and a CHM-example.chm file in the same local D:\_working folder. Please note window.showHelp opens a HTML help file (.chm) in an external application (Help Viewer hh.exe).

Please make shure to test this using Internet Explorer 11 (context menu, open with IE11). AFAIK - showHelp() isn't a javascript (or JScript) function - it's an Microsoft Internet Explorer DHTML method.

<!DOCTYPE html>
<html lang="en">
<head>
    <script type="text/javascript">

        function OpenHelpFile () {
            // open help file in help viewer - IE 11 only
            // --------------------------------------------------------
            // for optional use cases when CHM resides in another place
            // var DriveStr = "D:";
            // var SubFolderStr = "_working";

            var HelpFileName = "CHM-example.chm";
            var HelpFileStr = HelpFileName;

            // open help file topic in help viewer - IE 11 only
            // --------------------------------------------------------
            <!-- window.showHelp ("CHM-example.chm", null) -->
            alert ("attempted to launch the showHelp file. URL is: " + HelpFileStr);
            window.showHelp (HelpFileStr);
        }

        function OpenHelpTopic () {
            //  open help file topic in help viewer - IE 11 only
            // --------------------------------------------------------
            var DriveStr = "D:";
            var SubFolderStr = "_working";
            var HelpFileName = "CHM-example.chm";
            var HelpTopicStr = DriveStr + "\\" + SubFolderStr + "\\" + HelpFileName + "::" + "/garden/flowers.htm";   

            // open help file topic in help viewer - IE 11 only
            // --------------------------------------------------------
            <!-- window.showHelp ("D:\\_working\\CHM-example.chm::/garden/flowers.htm", null) -->
            alert ("attempted to launch the showHelp file. URL is: " + HelpTopicStr);
            window.showHelp (HelpTopicStr);
        }

        function OpenHelpTopicInNewTab () {
            // open help topic in new tab - only working inside IE11 using ms-its protocol
            // ---------------------------------------------------------------------------
            // "ms-its:D:\_working\CHM-example.chm::/garden/garden.htm"

            var ProtocolStr = "ms-its:";
            var DriveStr = "D:";
            var PathToFileStr = "\\_working\\CHM-example.chm";
            var HelpTopicStr = ProtocolStr + DriveStr + PathToFileStr + "::" + "/garden/garden.htm";

            alert ("attempted to launch the showHelp file. URL is: " + HelpTopicStr);

            // please note: window.open (!) ---------------------------------------------
            window.open (HelpTopicStr, null);
        }

    </script>
</head>
<body>
<p>Help Information www.help-info.de</p>
<hr />
<p>Open a help file</p>
<div>
    <button onclick="OpenHelpFile ();">Open a help file!</button>
</div>
<hr />
<p>Open a help topic</p>
<div>
    <button onclick="OpenHelpTopic ();">Open a help topic!</button>
</div>
<hr />
<p>Open a help topic in a new browser tab</p>
<div>
    <button onclick="OpenHelpTopicInNewTab ();">Open a help topic in a new browser tab!</button>
</div>
</body>

The button steps (2 and 3) are resulting in a the screenshot below (please note the second browser tab as result of third button).

You may want to download the above used CHM-example.chm file from my HTMLHelp (HH) info site see download section or download directly from CHM.

Please note, to open this CHM file right-click the saved file, click Properties, and then click Unblock.

JavaScript - open CHM file and topic