Page 1 of 1

"copy example" button to the CHM

Posted: Tue Feb 18, 2025 7:41 pm
by AZJIO
How to add a "copy example" button to the CHM reference file.

To get a list of files containing code samples, you need to search by <pre> tag.
1. Replace the <pre> tag with:

Code: Select all

<br /><a href="javascript:ClipBoard(pb);"><IMG title="Copy to Clipboard" style="margin: -16px 0px 0px 0px;" src="../copy.gif" border="0" align="right"></a>
<PRE class="codebox" id="pb">
2. Replace the </body></html> tag with

Code: Select all

<textarea ID="holdtext" STYLE="display:none;"></textarea><SCRIPT LANGUAGE="JavaScript">function ClipBoard(NumBlok){holdtext.innerText = NumBlok.innerText;Copied = holdtext.createTextRange();Copied.execCommand("Copy");}</SCRIPT>
</body></html>
3. We use the icon src="../copy.gif ", add it to the root folder. You can check in the browser how the button looks.
4. Compile the CHM help file and now it will have a copy code button without having to select the code text.

Necessary programs for searching and compiling (HTML Help Workshop)

But not everything is as perfect as we would like. Some blocks listing constants also have a <pre> tag. If there is more than one tag, then the "pb" identifier must be different, for example pb1, pb2, pb3, etc.

Code: Select all

id="pb"
ClipBoard(pb)