Quote:
Originally Posted by kovidgoyal
I dont understand what your issue is. If you want to call some JS function in an external script, just put the code that is calling it after the external script tag, since you are not marking the script as async, it will be loaded before the code using it is called.
|
Thanks for looking at this. I made a new test (below) to try to implement what I think you suggested. In the ebooks editor it works like I hoped. In atril document viewer it works like I hoped. In ebook-viewer I get:
Code:
$ ebook-viewer calibre_onload.epub
ERROR: clbr://internal.sandbox/book/__index__:2: Uncaught ReferenceError: accessFromImported is not defined
To me it looks as though the immediate script (below the <p> tag) is executed before the script from the imported file gets a chance to define the function.
JR
start.xhtml
Code:
<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>calibre call initialization function</title>
<script src="imported.js"></script>
</head>
<body>
<h1>calibre call initialization function</h1>
<p id="access-from-imported">static content for imported.</p>
<script><![CDATA[
accessFromImported();
]]></script>
</body>
</html>
imported.js
Code:
function accessFromImported() {
document.getElementById( "access-from-imported" ).appendChild( document.createTextNode( " added by accessFromImported" ) );
}