![]() |
#1 |
Member
![]() Posts: 22
Karma: 10
Join Date: Jun 2021
Device: Any ereader for Android or iOS
|
How to load javascript module in epub xhtml
I have an ebook (ebook1.epub) that loads a javascript file (script1.js) like so:
Code:
cat EPUB/xhtml/raw/ch1.xhtml <!--?xml version='1.0' encoding='UTF-8'?--> <!DOCTYPE html><html xml:lang="en-us" lang="en-us" xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:xlink="http://www.w3.org/1999/xlink"> <head> <script type="text/javascript" src="../../js/script1.js"></script> ... </head> ... </html> # -------------------------------------------------------------- cat EPUB/package.opf ... <item id="js4" href="js/script1.js" media-type="text/javascript"/> Code:
calibre ebook1.epub ------- Now, I need to use Javascript module file (ES6) (script2.js) The javascript module file is loaded like so: Code:
cat EPUB/xhtml/raw/ch1.xhtml <!--?xml version='1.0' encoding='UTF-8'?--> <!DOCTYPE html><html xml:lang="en-us" lang="en-us" xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:xlink="http://www.w3.org/1999/xlink"> <head> <script type="module" src="../../js/script2.js"></script> ... </head> ... </html> # -------------------------------------------------------------- cat EPUB/package.opf ... <item id="js4" href="js/script2.js" media-type="text/javascript"/> ``` Code:
calibre ebook2.epub Calling function from script2: - does not print anything to the terminal. - the terminal shows an error message: Code:
ERROR: clbr://internal.sandbox/book/EPUB/js/script2.js:0: Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec. Thanks, Avner |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,289
Karma: 27111238
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
what version of calibre, what OS? As far as I know, calibre does send mimetypes for js files. It's likely a bug in Qt WebEngine's custom URL scheme handling.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,289
Karma: 27111238
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
And I just tried it on the current calibre release, it works fine.
|
![]() |
![]() |
![]() |
#4 |
Member
![]() Posts: 22
Karma: 10
Join Date: Jun 2021
Device: Any ereader for Android or iOS
|
@kovidgoyal, thanks for replying
The Calibre version is 4.99.4. The OS is Ubuntu 20.04 Can you share a LINK TO Nn example with a call to javascript module? Maybe I'm doing something incorrectly. Thanks, Avner Code:
calibre --version calibre (calibre 4.99.4) lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.2 LTS Release: 20.04 Codename: focal |
![]() |
![]() |
![]() |
#5 | |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,685
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Quote:
Suggest you download and install the latest version from the calibre site ==>> https://calibre-ebook.com/ BR |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Member
![]() Posts: 22
Karma: 10
Join Date: Jun 2021
Device: Any ereader for Android or iOS
|
I installed the latest Calibre version (5.22.1) from here
After install, I was able to load module javascript files, and see messages from console.log() in the terminal where I launched Calibre from. Code:
cat EPUB/xhtml/raw/ch1.xhtml <!--?xml version='1.0' encoding='UTF-8'?--> <!DOCTYPE html><html xml:lang="en-us" lang="en-us" xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:xlink="http://www.w3.org/1999/xlink"> <head> <script type="module" src="../../js/script2.js"></script> ... </head> ... </html> # -------------------------------------------------------------- cat EPUB/package.opf ... <item id="js4" href="js/script2.js" media-type="module"/> When I ran calibre with Code:
calibre ebook2.epub I can see messages from Console.log() in the terminal. kovidgoyal, thanks for your help. Avner |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Javascript in ePub. | Vijay | ePub | 22 | 12-28-2023 09:43 AM |
Aura {A1} epub 3.0 renderer javascript support? | pluma | Kobo Reader | 1 | 01-13-2017 03:53 PM |
Hints for javascript in epub ? | fxp33 | Kobo Developer's Corner | 6 | 08-09-2014 01:18 PM |
Javascript in ePub | Techno4 | ePub | 9 | 11-05-2012 12:50 PM |
epub et javascript | zelda_pinwheel | Software | 9 | 12-09-2010 04:56 PM |