Viewing dynamically generated HTML in the HTML Help viewer
November 22nd, 2010
This is something I’ve blogged about twice before (in March 2004 and in January 2009), but going back to those topics just now neither of the solutions I gave at that time are working for me. So here’s the way to do it now.
The problem
The problem we’re trying to solve is how to debug a topic in a CHM file where you’ve got JavaScript that dynamically changes the HTML at runtime (i.e. when the topic is displayed in the Microsoft HTML Help viewer). If you’re debugging issues in WebHelp output you have the fabulous Firebug plugin that allows you (amongst other things) to click on objects in the output page and see what their HTML looks like right now. But unfortunately you can’t add Firebug to the help viewer. Or can you?
Online solution
This is the best solution, but it relies on you having:
- Internet access
- JavaScript enabled (a safe assumption as it’s probably JavaScript you’re debugging here)
- No firewall settings that might block code being downloaded from getfirebug.com (unlikely)
If any of the above aren’t true then you’ll need to use the offline solution (below).
The online solution uses the Firebug Lite bookmarklet to add much of the functionality of the Firebug plugin for Firefox to the browser pane within the HTML Help Viewer.
-
Do one of the following (these are just alternative ways of copying the same JavaScript to the clipboard):
Either: Right-click this link – Firebug Lite – and copy the link location (“Copy Shortcut” in IE).
Or: Copy the following code:
javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened'); - Right-click the title bar of the HTML Help Viewer.
-
Choose Jump to URL.

-
In the Jump to URL dialog box, paste the text you copied in step 1.

-
Click OK.
After a moment (while it downloads files) the Firebug panes are displayed across the bottom of the browser pane in the HTML Help viewer.
-
Click Inspect, then click an object in the topic pane.
The HTML for this object (including any dynamic modifications) is displayed in the HTML tab of the main Firebug pane:
Note: External JavaScript and CSS files aren’t recognised because they reside at another domain. So, when you click the CSS tab all you’ll see it “There are no rules in this stylesheet” and in the Script tab you’ll get “Access to restricted URI denied”. However, the functionality of the HTML tab is enough to make this technique extremely valuable for debugging.
Offline solution
The alternative is just to display the current, dynamically modified HTML in the browser pane. You can then select and copy/paste it into an editor for debugging.
To do this, copy and paste the following JavaScript into the Jump to URL dialog box:
javascript:'<xmp>'+window.document.documentElement.outerHTML+'</xmp>';
Note: The xmp element is deprecated and you shouldn't generally use it. However, in this case we know that we're using it in IE (the browser part of the HTML Help viewer) and IE, as of writing, still supports this element. If this stops being the case in future, the following is a less elegant (but standards-compliant) way of doing the same thing:
javascript:'<pre>'+window.document.documentElement.outerHTML.replace(/</g,'<')+'</pre>';
Potentially similar posts
- Convert escaped Unicode to HTML entities – January 2012
- Archived post summaries – June 2011
- How to: Get a white screen – June 2011
- Online JavaScript scratchpads – November 2010
- Use the existence of a file on the server to determine Javascript behaviour in the browser – November 2010

