iBooks:导入* .epub文件时可以使用localStorage吗? [英] iBooks: is it possible to use localStorage when importing a *.epub file?

查看:89
本文介绍了iBooks:导入* .epub文件时可以使用localStorage吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个示例epub文件,我可以在iBooks中读取该文件,其中包含iBooks将通过localStorage访问的交互式内容.我能够在chrome和firefox(不是IE)的浏览器上正常运行localStorage.

I'm trying to create a sample epub file that I can read in iBooks that will contain interactive content that iBooks will access via localStorage. I am able to get the localStorage piece working on the browser aok in chrome and firefox (not IE).

我注意到,当文件具有* .xhtml扩展名(只有* .html扩展名)时,localStorage javascript位不起作用.

I noted that the localStorage javascript bit does not work when the files have *.xhtml extensions, only *.html extensions.

我能够压缩html,opf和ncx并获得一个我可以在数字版本中阅读的epub,并且仅抛出与javascript内容相关的epubcheck错误.

I am able to zip up the html, opf and ncx and get an epub that I can read in digital editions and only throw epubcheck errors related to javascript stuff.

我首先尝试将其导入到iBooks,并且可以正常阅读,但该表格不是交互式的.然后,我在Google上搜索并发现一则帖子,说它必须位于iFrame中,而我确实这样做了.然后,我可以在表单中输入文本,但是本地存储位不起作用.

I first tried importing this to iBooks, and I could read it aok, but the form was not interactive. Then I googled and found a post saying that it need to to be in an iFrame, which I did. I was then able to enter text into the form, but the local storage bit did not work.

以下是2个相关的html文件:

Here are the 2 relevant html files:

<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
</head>
<body onLoad="writeStoredData( 'storedName' );" >

<div epub:type="chapter">

<h1>An HTML5 Ebook Sample</h1>
<p> A simple html5 form that uses local storage to hold user input info</p>
<ul><li>Does a device retain the info when the user moves from page to page? </li>
    <li>When the device is turned off and on?</li>
</ul>
<p>In this simple form, the body has an onLoad attribute that calls a function to load     the "name" from local storage. When the user enters input from a form the value is updated.     When the user closes the page and opens it again the value is still there.</p>
<br/>

<div class="formContainer">
<iframe class="content" src="form.html"></iframe>
</div>
<div id="storedName"></div>

<p>Go to <a href="ebook-sample-pg2.html">page 2</a>
</p>
</div>

<script>
    function writeStoredData( id ){

        var storedNameDiv = document.getElementById(id);
    storedNameDiv.innerHTML = "<p>The stored name is: <span class='selected'>"     + localStorage.getItem('somename') + "</span></p>";
    }   
</script>
</body>
</html>

和形式:(具有写入localStorage的功能)

and the form: (this has the function that writes to localStorage)

<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title>Epub3 Test Input Form</title>

</head><body>
<form>
Please enter your name: <input type="text" id="nameInput"/>
<input type="submit" value="enter" onClick="writeLocal();"     onSubmit="window.location.reload()"/>

</form>


<script>
        function writeLocal(){
            var submittedName = document.getElementById('nameInput').value;
            // calling it 'somename' to indicate user defined key
            localStorage.setItem('somename', submittedName);
            writeStoredData( 'storedName' );
    }


    function writeStoredData( id ){
        var storedNameDiv = document.getElementById(id);
        storedNameDiv.innerHTML = "<p>The stored name is: <span class='selected'>"     + localStorage.getItem('somename') + "</span></p>";
    }   
</script>

</body></html>

这是content.opf文件的清单:

and here is the manifest from the content.opf file:

  <manifest>
    <item id="js" href="javascript/ebook-test.js" media-type="text/javascript"/> 
    <item href="form.html" id="form1" media-type="application/xhtml+xml"     properties="scripted"/>
    <item href="ebook-sample.html" id="page1" media-type="application/xhtml+xml" properties="scripted"/>
    <item href="ebook-sample-pg2.html" id="page2" media-type="application/xhtml+xml" properties="scripted"/>
    <item href="toc.ncx" id="ncx" media-type="application/x-dtbncx+xml"/>
    <item id="toc" properties="nav" href="toc.xhtml" media-type="application/xhtml+xml"/>
  </manifest>

用javascript编写的位根本不会出现.我的下一步是尝试在iBooks Author中创建文件,但希望能够通过epub做到这一点.我知道iBooks应该能够做到这一点,因为我进行的大多数谷歌搜索都为iBooks Author带来了教程.

The bit written by javascript never appears at all. My next step is to try to create a file in iBooks Author, but was hoping to be able to do this with epub. I know that iBooks should be able to do this stuff, as most of the googling I did brought up tutorials for iBooks Author.

此外,我尝试使用javascript进行各种操作;我看到的大多数示例的代码都在html文件底部的标记中,但是我尝试在单独的* .js文件中进行操作,并且在head标记中没有区别.

Also, I tried various things with the javascript; most of the examples I saw had the code in a tag at the bottom of the html file, but I tried in a separate *.js file, and in the head tag, made no difference.

任何帮助,我们将不胜感激. bp

Any help greatly appreciated. bp

推荐答案

localStorage在Apple iBooks中已被禁用,因此您不希望在其渲染的EPUB中运行代码.

localStorage has been disabled in iBooks by Apple, hence you cannot hope to have your code running from within an EPUB rendered by it.

这篇关于iBooks:导入* .epub文件时可以使用localStorage吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆