简体   繁体   English

如何使用javascript读取epub内文件的内容

[英]How to read the contents of a file inside an epub using javascript

I need to read, inside a page of an epub3 book, the contents of one of the file of that same epub, being some data to process with a javascript function. 我需要在epub3书的页面内阅读同一epub文件之一的内容,这是一些需要使用javascript函数处理的数据。 Unfortunately, Javascript prevents from loading local files for security reasons. 不幸的是,出于安全原因,Javascript阻止加载本地文件。 (eg the File API only allows loading uploaded user files). (例如,文件API仅允许加载上载的用户文件)。

But for me in the context of an epub3, it makes sense and I didn't find any information in the IDPF EPUB3 documentation related to this topic. 但是对于我来说,在epub3的上下文中,这很有意义,而且我在IDPF EPUB3文档中没有找到与此主题相关的任何信息。

Any idea ? 任何想法 ?

OK. 好。 Let's clarify: 让我们澄清一下:

I have an epub3 with the following structure: 我有一个epub3,其结构如下:

<root>
    META-INF
        ...
    OEBPS
        pages
            page.xhtml
        data
            data.xml

In page.xhtml, I want to write in Javascript something like: 在page.xhtml中,我想用Javascript编写类似以下内容的代码:

<script type="text/javascript">
//pseudo code
var indata = readAsText("../data/data.xml"); // how to write that ???
var outdata = myfunction(indata);
</script>

Found the solution for ages, and realized that it had never been answered: So answering to my own question ;-) 找到了很久以来的解决方案,并意识到它从来没有被回答过:所以回答我自己的问题;-)

<script type="text/javascript">
    /* Load the file using HTTP GET */
    $.get( "../data/data.xml", function( indata ) {
    var outdata = myfunction(indata);
    }, 'text');
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM