HTML Redirection and other Tricks
June 24th, 2004
I was back on the microsoft.public.helpauthoring newsgroup* yesterday, getting help with some HTML Help problems I was having. During the course of a couple of discussions, Pete Lees reminded me about Rick Stone's useful set of Tips and Tricks, which he has collected into an HTML Help project. You can download a zip file containing the .chm files at:
www.robowizard.com/RoboWizard/NewProject.htm#Downloads/Tips_and_Tricks.htm
There's a lot of good stuff in there, including the fact that you can dig around in the behind the scenes data of a RoboHelp project by opening the .mpj file in Access. I hadn't realised that this file is a database containing a set of tables - one for each of the different parts of a help project (Windows, Merge Files, etc.).
I found another useful tip on Rick Stone's website. It's a fairly obvious idea - but then those are sometimes the best ones. Imagine you want to include in your help system a link to a large user manual in PDF form. When the user clicks the link you want the PDF to open up in a new browser window. Nothing difficult here, but the problem is that on slow machines this can take a while. The user clicks the link and thinks it's broken because nothing happens straight away.
To prevent this confusion you need to display an intermediate page saying something like "Please wait. The User Guide will be displayed shortly." To do this, make the link go to a page containing this message, and in the head of this intermediate page but the following meta tag:
<meta http-equiv=refresh content="1;URL=LargeUserGuide.pdf">
This tells the browser to start loading the PDF after one second (you'll probably want to change this to 0). All being well the message will remain on the screen while the PDF loads. When it loads it will do so in the same browser window. The effect is that the user gets some immediate feedback.
You can do the same thing by pointing all such links to a single redirection page containing JavaScript that works out which page to redirect you to. The good thing about this is that you only need to maintain one redirection page. The JavaScript section contains details of all the destinations, and you tell the JavaScript where to redirect to by including a code word in the URL of the page, in the form of an anchor reference. For example, if the redirection page is called redirection.file, you might call it with the URL redirection.file#UserGuidePDF. The script has another URL mapped to the code UserGuidePDF. Here's an example of the redirection page:
1: <html>
2: <head>
3:
4: <title>Redirection page</title>
5:
6: <!-- This file is used to get display a "please wait..." message
7: while the browser loads another file. -->
8:
9: <script language ="Javascript">
10: <!--
11: var Code = window.location.hash.substring(1);
12: var URL= "" ;
13:
14: if (Code == "UserGuidePDF") URL="PDFs/UserGuide.pdf" ;
15: else if (Code == "AdminGuidePDF") URL="PDFs/UserGuide.pdf" ;
16: else if (Code == "WordDoc") URL="Don't%20use%20spaces%20in%20file%20names.doc" ;
17: else if (Code == "SpreadSheet") URL="spreadsheet.xls" ;
18:
19: if (Code == "")
20: window.location.replace("homepage.html");
21:
22: if (URL != "")
23: window.location.replace(URL);
24: else if (Code != "")
25: alert("Error in redirect.file\n\n" +
26: "No URL has been specified for the anchor: \"" + Code + "\"");
27: //-->
28: </script>
29:
30: </head>
31:
32: <body> 33: <p>Please wait. The page you requested will be displayed shortly.</p>
34: </body>
35:
36: </html>
One of three things happens when you load this page:
1) If you call it with one of the anchors it knows about (e.g. redirect.file#UserGuidePDF), it displays the "please wait" message.
2) If you call it with an anchor it doesn't recognise, it displays an alert box, with an appropriate error message.
3) If you call it with no anchor, it redirects you to a default page.
Thanks to Rob Chandler (The Helpware Group website: http://helpware.net/htmlhelp/how_to_merge_ctx2.htm) for details of how to do this type of redirection.
Notes:
1) This is intended for HTML Help, so it only works in IE. However, with a bit of tweaking you could get it to work in other browsers.
2) I've called this file redirection.file rather than redirection.html so that it doesn't get parsed for a full-text search in the help file. I don't want it showing up in the HTML Help Viewer's search results if the user searches for "wait".
3) Thanks to Jean-Claude Manoli for his wonderful online code formatter (www.manoli.net/csharpformat), which I used to produce the nicely coloured/formatted HTML code you see above.
-----
*You can get to the microsoft.public.helpauthoring newsgroup at:
http://communities.microsoft.com/newsgroups/default.asp?icp=web_publishing_all&slcid=us&newsgroup=microsoft.public.helpauthoring
-----
Potentially similar posts
- Convert escaped Unicode to HTML entities – January 2012
- Viewing dynamically generated HTML in the HTML Help viewer – November 2010
- Fix “No topics found” issue in CHM output – November 2010
- Use the existence of a file on the server to determine Javascript behaviour in the browser – November 2010
- The four levels of software support – June 2010