I’ve written some JavaScript that allows you to sniff out Namespaces and Titles registered on your PC. You can also grab the path of a .HxS help file associated with a namespace/title.
- Download: h2Script1.00.zip
- Note: COM is involved so open the example file in Internet Explorer not Firefox. The example code should work in either your IE browser or within a HxS help file.
In HTML Help we could use JavaScript to dynamically create a link to an external file. For example a .wmv, .mp3, .pdf files stored in the same folder as the .CHM file. This is the best way to link to PDFs since you are not dealing with the ActiveX/COM and the PDF opens in AcroReader, not embedded in the HTML page.
For MS Help 2 the technique is slightly different. We need to access the MS Help 2 API (via its COM interface) to find out what H2 Namespaces andTitles are registered.
Script Functions
The script file ns_funcs.js contains 4 functions:
- NS_H2RuntimeInstalled() — Returns TRUE if Help 2 is installed on the PC.
- NS = NS_GetClosestMatch(Namespace) — Useful when you don’t know the MSDN language (namespace lang suffix).
Example: NS_GetClosestMatch(“ms.vscc”) will return ms.vscc.3082 on a Spanish PC. - NS = NS_IsValid(Namespace) — Returns the namespace in correct case if found. Or empty string if not found.
- NS = NS_GetNSList() — Returns a multi-line string containing detailed info on all Namespaces registered on the PC.
The script file ns_path.js contains 2 functions:
- NS_GetHxSPath(Namespace, Title) — Returns the path to the .HxS help file associated with a Namespace and Title.
- NS_GetHxSDir(Namespace, Title) — Returns just the directory (with trailing \) associated with a Namespace and Title.
these functions return .HxS path information given a Namespace and Title name.
For example the following namespace/title is associated with .HxS file dv_dexplore.hxs
- Namespace: MS.Dexplore.v80.en
- Title: dv_dexplore
Example 1
var s1 = NS_GetHxSPath(“MS.Dexplore.v80.en”, “dv_dexplore”);
var s2 = NS_GetHxSDir(“MS.Dexplore.v80.en”, “dv_dexplore”);
s1 returns:
C:\Program Files\Common Files\Microsoft Shared\Help 8\1033\dv_dexplore.hxs
s2 returns:
C:\Program Files\Common Files\Microsoft Shared\Help 8\1033\
So… you can now dynamically create a link to a file that lives outside your help next to your .HxS help file.
Example 2
Some quick examples of linking to external files
<SCRIPT Language="JScript">
function OpenH2Link(filename) {
//This will find the Namespace for the current MSDN language. MS.Dexplore.v80.en for English PC
var ns = NS_GetClosestMatch("MS.Dexplore.v80");
//This returns the directory of the .HxS file associated with ns\title
var dir = NS_GetHxSDir(ns, "dv_dexplore");
//Finally load the file
var fn = 'file:///' + dir + filename;
location.href = fn;
}
</SCRIPT>
<a href="#" onClick="javascript:OpenH2Link('Somefile.pdf');">ClickMe</a>
<SCRIPT Language="JScript">
document.writeln('<a href="file:///' + NS_GetHxSDir('MS.Dexplore.v80.en', 'dv_dexplore') + 'SomeFile.pdf">ClickMe</a>');
</SCRIPT>
Enjoy
Rob