2

I'm using a MacBook Air and have been looking into ePub creation. I've taken a copy of the epub3 boilerplate from github click here. I have in a javascript file added the following

var txt = document.createTextNode(" This text was added to the DIV.");
document.getElementById('contenty').appendChild(txt); 

<script src='../js/main.js'></script>

When I open the compiled epub in iBooks it doesn't show This text was added to the DIV. in the div #contenty.

Using Kitabu it actually works but is there a way to get Javascript to work in iBooks?

Thanks

ngplayground
  • 20,365
  • 36
  • 94
  • 173

1 Answers1

5

Javascript will most definitely work in iBooks: just make sure to include your JS files in the opf manifest as items:

<item id="[someUniqueID]" href="[fileLocation/fileName.js]" media-type="text/javascript"/>

You also need to declare the page(s) that reference the script file as scripted in the OPF:

<item id="[pageID]" href="[pageLocaiton.xhtml]" media-type="application/xhtml+xml"  properties="scripted" />

Note: you can get sideloading to work even without the above fixes, but you won't be able to actually put the book in the iBookstore without them.

Right now, your JS code won't work: because it is executing before the page loads: try doing a <body onload="init()"> and wrap your second line of code (document.getElementById....) in an function init(){}.

Best of luck any happy Scripting!

Alex Milewski
  • 419
  • 2
  • 8
  • I got it working on iBooks on the Mac but when I try it in BlueFire on an Android phone it doesn't work – ngplayground May 19 '14 at 15:41
  • 1
    Bluefire doesn't have full ePub3 support: your question was specific to iBooks so I just spoke to that... If you are looking for an Android reader, I would wait until the end of June and Kobo should have full ePub3 support! – Alex Milewski May 20 '14 at 16:18