Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 02-18-2025, 11:01 AM   #1
Ilcaa
Junior Member
Ilcaa began at the beginning.
 
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
Attached Files
File Type: epub TEST_EPUB_PARSE.epub (2.8 KB, 36 views)
Ilcaa is offline   Reply With Quote
Old 02-18-2025, 12:09 PM   #2
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
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.
KevinH is offline   Reply With Quote
Advert
Old 02-18-2025, 01:46 PM   #3
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,670
Karma: 23468403
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by Ilcaa View Post
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
You'll need to add onload to actually load the script:

Code:
<body onload="javascript:init()">
And as KevinH has already pointed out, you'll need to enable the Javascript option in Sigil.

However, using JavaScript in this way wouldn't be useful, if you actually want to permanently change text in the epub.
Doitsu is offline   Reply With Quote
Old 02-18-2025, 02:03 PM   #4
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
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>
...
But using onload to invoke the function you linked in is much nicer.

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.
KevinH is offline   Reply With Quote
Old 02-18-2025, 04:28 PM   #5
Ilcaa
Junior Member
Ilcaa began at the beginning.
 
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
Ilcaa is offline   Reply With Quote
Advert
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 12:10 PM.


MobileRead.com is a privately owned, operated and funded community.