![]() |
#1 |
Junior Member
![]() Posts: 3
Karma: 10
Join Date: Dec 2011
Device: Nook
|
JS script not running in EPub, sample attached
hello, i am trying to run a JS script that places each sentences into its own line.
This JS script works because i can successfully run it on my browser on any website, BUT i follwed the instructions for adding JS scripts to EPub via Sigil and I cant get it to work. can you take a look (file attached) seems striaght forward... 1. add JS Script to Misc folder. 2. select the xHTML file, right click and select "link JS File" 3. Sigil adds script tags to the xHTML pointing to JS Script 4. save as EPub i am attaching a very small sample with the script. If someone could correct it and let me know what I was missing that would be great. Thanks for the help |
![]() |
![]() |
![]() |
#2 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,377
Karma: 5581842
Join Date: Nov 2009
Device: many
|
Have you enabled javascript in Sigil Preferences? It is off by default for security reasons.
Are you creating an epub3? Epub2 does not support javascript. What e-readers have you tested it with? Not all epub3 e-readers support javascript? And no epub2 only e-readers do that I know of. Where or how is your javascript function invoked? Defining a javascript function does not invoke it. And fwiw, scripting the nav which is meant to always be machine parseable is probably not the best idea. Last edited by KevinH; 02-18-2025 at 12:53 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,670
Karma: 23468403
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Code:
<body onload="javascript:init()">
However, using JavaScript in this way wouldn't be useful, if you actually want to permanently change text in the epub. |
|
![]() |
![]() |
![]() |
#4 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,377
Karma: 5581842
Join Date: Nov 2009
Device: many
|
Yes, without the onload to actually invoke your javascript function you would have to manually invoke it someplace just before the ending body tag:
Something like: Code:
... <script type="application/javascript" src="../Misc/Script0001.js" ></script> </head> <body> <p>this is some text. This more text. Try another type of texting.</p> <p>this is some text. This more text. Try another type of texting.</p> <p>this is some text. This more text. Try another type of texting.</p> <script type="application/javascript">init()</script> </body> ... Alternatively you could instead add the call to invoke init() to the end of the script itself and then link in the script not in head but instead just before the body close tag. But in my opinion Doitsu's approach is the best/most compliant. Last edited by KevinH; 02-18-2025 at 02:22 PM. |
![]() |
![]() |
![]() |
#5 |
Junior Member
![]() Posts: 3
Karma: 10
Join Date: Dec 2011
Device: Nook
|
thanks for the response...
1. i activeated the JS script function in 'Preferences' within Sigil. 2. I added the Onload event (both methods proposed above) everything seems to work as intended, and the sentences get parsed 3. i tried it on Calibre reader and it works good, i tried it on some other desktop readers, some worked out did not... BUT right now, its what i expected. Thanks for the replies and assistance |
![]() |
![]() |
Advert | |
|
![]() |
Thread Tools | Search this Thread |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Clara HD Running script from NickelMenu returns too early | nickelclone | Kobo Reader | 6 | 08-11-2024 09:00 PM |
Running calibredb from a cron script | rolgiati | Server | 13 | 03-05-2019 04:43 PM |
Error when running Igor's script | gloorfindel | Amazon Kindle | 3 | 11-07-2010 03:14 PM |
Try out this ePub sample? | UniversalisPub | ePub | 15 | 09-09-2009 11:47 AM |
Running a script on-demand? | pepak | Sony Reader Dev Corner | 1 | 04-27-2009 11:22 AM |