How to link external javascript file in a DITA-OT HTML5 output

Post here questions and problems related to editing and publishing DITA content.
gevinl
Posts: 3
Joined: Fri Jul 09, 2021 11:22 am

How to link external javascript file in a DITA-OT HTML5 output

Post by gevinl »

I would like to add a link to an external JavaScript file in my DITA-OT output HTML5 file, how do I achieve this?

|--[js]
| |--custom.js
|--[css]
| |--custom.css
|--index.html
|--topic01.html
|--topic02.html

I want to add a line <script src="custom.js"></script> in the <head> tag of an output html file.

Please advise.

Thank you.


Gevin
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to link external javascript file in a DITA-OT HTML5 output

Post by Radu »

Hi Gevin,

There is a transformation parameter named "args.hdf":
https://www.dita-ot.org/dev/parameters/ ... __args.hdf

you can point it to a file containing inside the "<script src="custom.js"></script>" content.
The publishing will not automatically copy the "custom.js" to your output folder though but the HTML files will contain the updated header.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
gevinl
Posts: 3
Joined: Fri Jul 09, 2021 11:22 am

Re: How to link external javascript file in a DITA-OT HTML5 output

Post by gevinl »

Hi Radu,

Thank you very much for your suggestion.

Yes, it is really work, and solve my problem.

P.s. I uses the example I found in https://www.dita-ot.org/dev/topics/html ... cript.html to write the XML file for args.hdf. It's working.


Cheers!

Gevin
gevinl
Posts: 3
Joined: Fri Jul 09, 2021 11:22 am

Re: How to link external javascript file in a DITA-OT HTML5 output

Post by gevinl »

Radu wrote: Fri Jul 09, 2021 12:54 pm
There is a transformation parameter named "args.hdf":
https://www.dita-ot.org/dev/parameters/ ... __args.hdf

you can point it to a file containing inside the "<script src="custom.js"></script>" content.
The publishing will not automatically copy the "custom.js" to your output folder though but the HTML files will contain the updated header.
Hi Radu,

After successfully using "args.hdf" in my HTML5 transformation, I tried to use same method for 'DITA Map EPUB' transformation. But the transformation fail to add a line in the <head> tag in the pages of the output EPUB.

I did try to use args.hdr and args.ftr, but all fail to write any code within the output pages too.

Do you have any idea?

Thanks & regards,
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to link external javascript file in a DITA-OT HTML5 output

Post by Radu »

Hi,

I reproduced the problem and added an internal issue to investigate this further, if I come up with a possible fix I will reply back on the thread.
In the meantime if you use Oxygen's Archive browser view to edit the XHTML documents from the EPUB archive and add the extra javascript inside them, does that work in an EPUB reader? Because there may be limitations related to this as well.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply