03-03-2023, 11:09 AM | #1 |
Junior Member
Posts: 2
Karma: 10
Join Date: Apr 2022
Location: •••••••
Device: pixel3xl
|
javascript in epub
This is a development question.
I'm an experienced developer in other contexts, but entirely new to epub. I'm writing a Python utility to convert my website to epub3 I am finally getting output epubs that validate with epubcheck. Error free. I start with HTML fragments scraped from a website. make a recursive list of all links on all pages, as a text file in sequential order Loop through that link list line by line and make calls to python codes using ebookLib, that make a new epub. (epub3 fwiw) The epub I get fails with errors if anything like: loading="lazy" (css) onClick="bigImage(this)" (javascript) ...remain in the HTML fragments. I get an epub that does validate if I strip all that stuff first. Is there a way to configure something in content.opf perhaps, so that js and css stuff would not have to be stripped? The error I get for that stuff is ERROR(OPF-014): The property 'scripted' should be declared in the OPF file. How would I declare it? I don't expect javascript to work inside an epub reader. But it wold be handy if I did not have to strip it out. Do any epub readers support any subset of javascript in the epub? |
03-03-2023, 11:33 AM | #2 |
Bibliophagist
Posts: 34,229
Karma: 144198474
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
JS is supported in epub3 but not epub2. And even in epub3, only a relatively small subset is of real use. As for adding scripted in the opf file? You need to add a properties="scripted" in the appropriate places. See the example below:
Code:
<item href="Text/File_with_script.xhtml" id="File_with_script.xhtml" media-type="application/xhtml+xml" properties="scripted"/> |
Advert | |
|
03-03-2023, 04:24 PM | #3 | |||
Wizard
Posts: 1,527
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
On the other hand, also you can select the command "Tools/Epub3 Tools/Update Manifiest Properties" and all the changes will be made on the .opf file. Quote:
Quote:
|
|||
03-04-2023, 05:17 AM | #4 | |
the rook, bossing Never.
Posts: 10,649
Karma: 83693763
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper11
|
I know some people are fans of epub3, evangelists for it, but:
1) Only a subset of Javascript works on epub3. 2) Only a tiny number of apps fully support epub3 3) The majority of physical ereaders have very little or no epub3 support. 4) The majority of physical ereaders (inc Kindle) have little or no javascript support 5) A real ebook doesn't need any Javascript shouldn't use any. 6) Javascript execution creates a possible malware vector. Quote:
If you really need interactive (the reason for Javascript) consider a framework to produce iOS and Android apps. This of course can't sell via the ebook stores that sell about 99% of ebooks, but most of those won't distribute ebooks with Javascript (Amazon). I've Aldiko, Bluefire, Lithum and Pocket Book on Android. I've about 500 bought ebooks (since 2013 and from four stores) and about 5,000 PD ebooks (since about 2002). Not a single ebook has Javascript. Not a single ebook was delivered or downloaded in epub3. Last edited by Quoth; 03-04-2023 at 05:22 AM. |
|
03-04-2023, 09:25 AM | #5 | |||||||||
Wizard
Posts: 1,527
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Quote:
Quote:
Quote:
Quote:
with a bigger font-size: You won't be able. And no matter the user change the font-size, the layout is maintained by the script. Below anyone can check the respective epub3 with the respective script to get that layout. The possibilities of epub2 to work with poetry are very poor compared with epub3 plus javascript. Poetry Test.epub And try to get with an epub2 the following animations usefull in children's books: Text Animations.epub And watch the following .xhtml code: Code:
<h1>TITULUS*HIC*EST</h1> <p class="start">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ac tellus nunc. Phasellus imperdiet leo metus, et gravida lacus. Donec metus ligula, elementum at pellentesque pellentesque, suscipit ac nunc. Etiam lobortis, massa ac aliquam auctor, augue nisl sagittis urna, at dapibus tellus erat ullamcorper ligula. Praesent orci dui, pulvinar id convallis a, faucibus non mauris.</p> Under epub2, you should have to add a lot of additional code to get something similar. In the epub3 I attach below, you can see how easy is to get those effects with javascript. nthEverything Test.epub Of course, I'm not writting all this to try to convence you; I write this in order that anyone that is reading this thread can judge by itself if are true your statements. Quote:
Quote:
Quote:
Quote:
Again, try to get the poetry layout I uploaded with an epub2. And I have a lot of cases more than I don't want to publish here (I have my secrets) that are able to demonstrate the power of javascript. But for now what I posted is enough. Last edited by RbnJrg; 03-04-2023 at 10:22 AM. |
|||||||||
Advert | |
|
03-04-2023, 10:38 AM | #6 |
the rook, bossing Never.
Posts: 10,649
Karma: 83693763
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper11
|
Animations are for APPS not ebooks.
And I do know about javascript. I do know about multimedia design & websites, inc server side code. More than 20 years experience. I know about writing apps, desktop programs and video production. Once you add animation or interaction or video or sound, it's no longer a book. It's best done as an app and not pretending to be a book. Poetry works fine in epub2. Javascript is a stupid lazy way to do static layout, which is all an ebook should have. We have different definitions of what an eBook is. But stop being insulting just because you are an avid promoter of the epub3 spec. The OP and title is about "javascript in epub". My point is that most ebook sales and most physical ereaders and the store apps don't have javascript. If javascript is really needed it's not a real ebook. Sure you can use epub3. Good luck on selling that with working javascript in the major selling ebook stores compared with better features in an iOS and Android app. Last edited by Quoth; 03-04-2023 at 10:47 AM. |
03-04-2023, 06:37 PM | #7 | ||||||||||
Wizard
Posts: 1,527
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Words said by someone who knows nothing about the subject.
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Stick to epub2 if you wish, but you won't be able to stop the advance of the epub3 format. Sooner rather than later you will have to dedicate time to learn about the subject that now you are boldly writing. And please don't forget to post your epub2 that mimics the layout of my epub3 with javascript regarding poetry. I look forward to seeing that wonder. |
||||||||||
03-09-2023, 04:13 PM | #8 |
Resident Curmudgeon
Posts: 73,510
Karma: 126422064
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
I tried the nthEverything.epub on my Libra 2 and it did not work. It did not work in the Calibre viewer. It did work in the Calibre editor preview.
|
03-10-2023, 08:40 AM | #9 |
Wizard
Posts: 1,527
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Yes, you are right. As I said, I have my secrets It's neccesary to employ some things more in order to get the effect you can get with the script and that it works everywhere. It took to me a lot of time to know how to adapt scripts for epub3 and for now, I am not going to do public the procedure for this particular case. Sorry and please, don't get it wrong.
|
Thread Tools | Search this Thread |
|
Similar Threads | ||||
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 |