ePub and Javascript

你。 提交于 2020-01-12 10:15:30

问题


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


回答1:


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!



来源:https://stackoverflow.com/questions/23679325/epub-and-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!