FAQ‎ > ‎HV 1.0 Links‎ > ‎

<img> Notes

There are some interest quirks to HV 1.0 and how it expands links. All these examples use SelfBranded=true.

Here are my test files
  • h3m.js
  • html\test.htm
  • images\bob.gif
  • script\externalscript.js
You can download the source at the end of this page.

Embedded Script - Use of <!-- -->

This text merges OK

<script type="text/javascript">
<!--
function ShowProdLogo1() {
  var msg = '<' + 'img src' + '="images/bob.gif" />';
  document.write(msg);
}
-->
</script>

This wont merge unless you wrap your embedded script in <!-- --> like above. 

<script type="text/javascript">
function ShowProdLogo2() {
  var msg = '<' + 'img src' + '="images/bob.gif" />';
  document.write(msg);
}
</script>

Here's the merge error...

An error occurred while updating local content: System.Xml.XmlException: Name cannot begin with the ''' character, hexadecimal value 0x27. Line 38, position 15.

Conclusion: wrapping embedded script in <!-- --> shields your code from the Agent XML parser.

Embedded Script - Render time expand

Notice I have chopped up the second func string? This causes the second image to fail.

<script type="text/javascript">
<!--
function ShowProdLogo1() {
  var msg = '<img src="images/bob.gif" />';
  document.write(msg);
}
function ShowProdLogo2() {
  var msg = '<'+'img src'+'="images/bob.gif" />';
  document.write(msg);
}
-->
</script>

A view source reveals... 

<script type="text/javascript">
<!--
function ShowProdLogo2() {
  var msg = '<img src="http://127.0.0.1:47873/help/0-3588/ms.help?content/Helpware/store/helpware.mshc;/images/bob.gif" />';
  document.write(msg);
}
function ShowProdLogo3() {
  var msg = '<'+'img src'+'="images/bob.gif" />';
  document.write(msg);
}
-->
</script>

Conclusion: Agent scans the whole file looking for recognizable <img src=""> type patterns. If found they expand to a full path to the package in the store (same as a normal <img src=""> link). The text can be anywhere in the doc.

Calling both these functions results in...


Right-click properties dialog...

http://127.0.0.1:47873/help/0-3588/ms.help?content/Helpware/store/helpware.mshc;/images/bob.gif

and

http://127.0.0.1:47873/help/0-3588/images/bob.gif

Conclusion: Anything Agent is unsure of... it prefixes just the protocol (not the package path): http://127.0.0.1:47873/help/0-3588/


Embedded Script - More Paths

These paths point to the location of the package in the store

<!--
function ShowProdLogo4() {
  var msg = '<img src="ms.help?content/Helpware/store/helpware.mshc;/images/bob.gif" />';
  document.write(msg);
}
function ShowProdLogo5() {
  var msg = '<'+'img src="ms.help?content/Helpware/store/helpware.mshc;/images/bob.gif" />';
  document.write(msg);
}
-->

The first fails with an X image. Agent prefixes with the full path to the package in the store so we end up with double path.

http://127.0.0.1:47873/help/0-4732/ms.help?content/Helpware/store/helpware.mshc;/ms.help?content/Helpware/store/helpware.mshc;/images/bob.gif

The second (which is chopped up so Agent misses the pattern) works fine.. Image properties give ...

http://127.0.0.1:47873/help/0-4732/ms.help?content/Helpware/store/helpware.mshc;/images/bob.gif

External Script File 

Let's put the script out in an external file now

<script type="text/javascript" src="script/externalscript.js"></script>

As you might guess the Agent parser works on patterns found in the topic file and does not see script in the external file. 

The effect is similar to when we broke up the patterns into short strings (above).

function ShowProdLogoX1()
{
  var msg = '<img src="images/bob.gif" />';
  document.write(msg);
}

function ShowProdLogoX2()
{
  var msg = '<img src="ms.help?content/Helpware/store/helpware.mshc;/images/bob.gif" />';
  document.write(msg);
}

The first image shows X image (fails to find the image). While the second displays OK.

Properties dialog shows...

http://127.0.0.1:47873/help/0-4456/images/bob.gif   (points to nothing - shows as X image)

the second shows ok

http://127.0.0.1:47873/help/0-4456/ms.help?content/Helpware/store/helpware.mshc;/images/bob.gif


External Script File - Fix

It's not convenient to hardwire the package path into URLs (although maybe if you have several packages, all using a single package of images it works well). In most cases it would be nice to have a global var that gives a path to the current package.

Build 59 of mshcMigrate contains a new version of h3m.js (release 4) - a general script file for fixing links.

It has 3 new global vars you can use. 

Here they are with example paths...

h3m_docPackagePath=http://127.0.0.1:47873/help/0-3400/ms.help?content/Helpware/store/helpware.mshc;/

h3m_docPackageShortPath=ms.help?content/Helpware/store/helpware.mshc;/

h3m_docProtocol=http://127.0.0.1:47873/help/0-3400/

Note: h3m_docPackagePath = h3m_docProtocol + h3m_docPackageShortPath

When run outside the MS Help Viewer 1.0 environment these 3 vars are empty strings. 

Example: 

1. Add h3m.js to the root of your project. Add a h3m.js include statement to the topic header.
    (Alternatively let mshcMigrate > Migrate add h3m.js to your files -- see Migrate options)

<script type="text/javascript" src="h3m.js"></script>

2. Add h3m_docPackageShortPath to your external script file.

function ShowProdLogoX3()
{
  var msg = '<img src="' +h3m_docPackageShortPath+ 'images/bob.gif" />';
  document.write(msg);
}

Now the property dialog for the image shows the correct full path:

http://127.0.0.1:47873/help/0-5628/ms.help?content/Helpware/store/helpware.mshc;/images/bob.gif




ċ
helpwareLinkTest.zip
(8k)
Robert Chandler,
May 21, 2010, 12:08 AM
Comments