javascriptactionscriptlaunchchmexternalinterface

Open CHM help file to a specific page via JavaScript


There are many posts on this topic here, but none are solutions for launching a CHM helpfile from a web page.

Background:

The path to the CHM file and to each page within it are taken from a JSON file, and depending on which page needs to be accessed in the CHM, the link is concatenated. An example of this is chm/myHelp.chm::cat2page1.html.

So with ActionScript, when the user clicked a button, this function created the full string passed to a JavaScript function named "callJavascript" in the containing HTML page, which in turn opened the CHM file to the correct page:

private function launchURL(e:MouseEvent) {
        if (_helpLibIndex != "" && _myHelpLink != "") {
            // ex: JavaScript:   callJavascript('chm/GloCyte.chm::cat2page1.html')
            var variableStr:String = _helpLibIndex + "::" + _myHelpPageLink;
            ExternalInterface.call("callJavascript", variableStr );
        }
    }

And the JavaScript on the HTML page hosting the Flash swf:

<script type="text/javascript">
        function callJavascript(str) {
            //window.alert(str);
            window.showHelp(str);
        }
    </script>

Should be easy to convert to just straight JS - right? I have many problems unfortunately.

Here is my JS code in the new HTML5 page. The _helpLibIndex and _myHelpLink are previously retrieved from the imported JSON file:

function launchURL() {
if (_helpLibIndex != "" && _myHelpLink != "") {
   // appending myHelpLink gives 404 error.
   // leaving it off kinda launches the CHM, but no content is viewable in the body area 
   // example string = 'chm/myHelp.chm::cat2page1.html'

   var variableStr = _helpLibIndex + "::" + _myHelpLink;

   window.showHelp(variableStr);

   console.log("attempted to launch the showHelp file. URL is: " + variableStr);

}

I don't quite understand the difference between ActionScript working in this case, and JavaScript not, since the final call in both cases is JS from the hosting web page. Any help is hugely appreciated!


Solution

  • 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. Maybe this has been fixed differently.

    I hope to give you an idea, but you'll have to adapt it for your needs (you mentioned using IE11). I have no experience with Flash ActionScript because there has always been a security issue with it as well. So, I don't know why ActionScript is working in this case, and JavaScript not.

    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. Only Internet Explorer (NOT Microsoft Edge browser) could load a locally path like:

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

    enter image description here

    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, 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).

    enter image description here

    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.

    Edit: (after comments)

    As a first step after saving this CHM file in a local drive: Please check if after double-clicking on the CHM file the content is completely shown in the topic window on the right.

    If not please note - to open this CHM file right-click the file, click Properties, and then check Unblock and click OK as shown in the screenshot below:

    enter image description here

    After creating the test.htm from the code above in the same directory make sure to open with Internet Explorer and to Allow Blocked content.

    The message with the button at the bottom of the browser window will disappear automatically after about 10 seconds for security reasons.

    enter image description here