ePub和Javascript [英] ePub and Javascript
问题描述
我正在使用MacBook Air并一直在研究ePub的创建。我从github 点击这里获取了epub3样板的副本。我在javascript文件中添加了以下内容
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>
当我在iBooks中打开已编译的epub时,它不会显示此文本已添加到DIV。
中的div #contenty
。
When I open the compiled epub in iBooks it doesn't show This text was added to the DIV.
in the div #contenty
.
使用 Kitabu 它实际上有效,但有没有办法让Javascript在iBooks中运行?
Using Kitabu it actually works but is there a way to get Javascript to work in iBooks?
谢谢
推荐答案
Javascript绝对可以在iBooks中使用:只需确保将您的JS文件作为项目包含在opf清单中:
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"/>
您还需要声明引用脚本文件的页面在OPF中编写脚本:
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" />
注意:即使没有上述修复,您也可以进行侧载工作,但是您将无法使用实际上把它放在没有它们的iBookstore中。
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.
目前,您的JS代码无效:因为它在页面加载之前执行:尝试执行< body onload = init()>
并将第二行代码(document.getElementById ....)包装在函数init(){}中。
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!
这篇关于ePub和Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!