Hello,
When converting an EPUB to PDF, in the custom "Header Template" section, I would like to use JavaScript in order to show the closest text of a given tag type, say, whatever is the value o the closest <h2>.
In order to do that, I tried to enhance the JavaScript example provided in the documentation, for example:
<header>
...
<div></div>
<script>
var thisDiv = document.currentScript.parentNode.querySelector("d iv");
var first = document.getElementsByTagName('h2').firstChild[0];
thisDiv.innerHTML = "" + first.innerHTML
</script>
...
</header>
But the problem with that code, is that the DOM has not been evaluated at the time where I try to grab the H2 content. And the normal JavaScript tricks to overcome this problem (adding "defer" or "module" to the <script> tag, or putting it all inside the document's load event), also don't seem to work.
So, my question is: Only the predefined variables such as _SECTION_ or _TOP_LEVEL_SECTION_ are available in the header script? Is it not possible to grab the value of the "closest()" text of a specific tag type?
When converting an EPUB to PDF, in the custom "Header Template" section, I would like to use JavaScript in order to show the closest text of a given tag type, say, whatever is the value o the closest <h2>.
In order to do that, I tried to enhance the JavaScript example provided in the documentation, for example:
<header>
...
<div></div>
<script>
var thisDiv = document.currentScript.parentNode.querySelector("d iv");
var first = document.getElementsByTagName('h2').firstChild[0];
thisDiv.innerHTML = "" + first.innerHTML
</script>
...
</header>
But the problem with that code, is that the DOM has not been evaluated at the time where I try to grab the H2 content. And the normal JavaScript tricks to overcome this problem (adding "defer" or "module" to the <script> tag, or putting it all inside the document's load event), also don't seem to work.
So, my question is: Only the predefined variables such as _SECTION_ or _TOP_LEVEL_SECTION_ are available in the header script? Is it not possible to grab the value of the "closest()" text of a specific tag type?