最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - ePub and Javascript - Stack Overflow

programmeradmin2浏览0评论

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 piled 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

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 piled 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

Share Improve this question asked May 15, 2014 at 13:12 ngplaygroundngplayground 21.7k37 gold badges98 silver badges174 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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!

发布评论

评论列表(0)

  1. 暂无评论