You can open document files left outside your ebook, but you need to make some changes to your HTML code. The best would be to use an HEScript script function. This function would be invoked from your HTML code: it will open any file you specify with a parameter.
The file that has to be opened must be in the same folder as the output EXE file or in a subfolder.
Just follow these steps:
1) We create the HEScript function. Open your HTML Executable project and go to the Script Manager. Double-click the “UserMain” script to open the script editor.
2) Add this function code:
procedure OpenAFile(Filepath: String); var EbookPath, MyFile: String; res: integer; begin EbookPath := GetGlobalVar("HEPublicationPath", ""); MyFile := IncludeTrailingPathDelimiter(EbookPath) + FilePath; res := OpenFile(MyFile, "", SW_SHOWNORMAL); if res < 32 then begin MessageBox("Error while opening: " + MyFile + ". Error code: " + inttostr(res), "Launch Error", MB_OK+MB_ICONERROR); exit; end; end;
3) Click Save Script.
4) Edit the HTML page with the links that should open the file. Just replace the links with the HTML code:
<a href="hescript://UserMain.OpenAFile|PATH TO YOUR DOCUMENT">Open my document</a>
PATH TO YOUR DOCUMENT with the relative path to the file you want to open (do not remove the
Be sure to encode non-ASCII characters of the path for the URL. URL encoding replaces unsafe ASCII characters with a
% followed by two hexadecimal digits. For instance, spaces in filenames should be replaced by
%20. To convert characters online, you will find an application at: http://www.w3schools.com/tags/ref_urlencode.asp
If you want a link that opens
mydocument.txt, use this HTML code:
<a href="hescript://UserMain.OpenAFile|mydocument.txt">Open my document</a>
If your file is inside a subfolder, use a path relative to the folder that contains the publication .EXE file. For instance, I want to launch the file
my folder\my document.mp3:
<a href="hescript://UserMain.OpenAFile|my%20folder\my%20document.mp3">Open the MP3</a>
Compile your project and that’s all.
Copyright G.D.G. Software 2019. All rights reserved