天天看點

ibooks的epub書使用input

環境:ios8,ibooks,chrome43

需要做個epub電子書,頁面帶有輸入框,但是直接添加<input>節點是不可編輯的,這還挺麻煩的,搜尋了下bing/yahoo(百度沒搜到),說是使用iframe+html實作,

但是基于webkit的chrome不支援本地的iframe資料互動(http://blog.csdn.net/dragoo1/article/details/47304335)

于是采用動态建立iframe方法,如下

chapter-001.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<html xml: xmlns="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title/>
<meta name="viewport" content="width=960, height=640"/>
<script type="text/javascript" src="jquery.js" />
<script type="text/javascript" src="quiz1.js" />
</head>
<body>
<div id="div1">
</div>
</body>
</html>
           

quiz1.js

$(document).ready(function() {
        var ifr_doc;
        var iframe = document.createElement('iframe');
        var ifr = document.body.appendChild(iframe);
        ifr_doc = ifr.contentWindow.document;

        ifr.frameborder = '1px';
        ifr.height = '100px';
        ifr.width = '200px';
        ifr.style.display = 'inline';

        var loadjs = "<html><body>Please enter your name: <input type=\"text\" id=\"nameInput\"/></body></html>";

        ifr_doc.open();
        ifr_doc.write(loadjs);
        ifr_doc.close();
});
           

jquery.js就從網上下個吧。。。

參考:

http://stackoverflow.com/questions/14552474/ibooks-is-it-possible-to-use-localstorage-when-importing-a-epub-file

繼續閱讀