如何从远程URL加载文件到JSZip?

时间:2017-10-18 00:01:54

标签: javascript jquery jszip

有没有办法从给定的URL加载文件到Zip?

像这样:

var zip = new JSZip();
zip.file("file.txt", "/site.net/files/file.txt");

更新

我正在暂停这个例子:http://stuk.github.io/jszip/documentation/examples/downloader.html

我尝试了这段代码,但它没有用。 我从github下载了脚本,这是我的例子:

<html>
<head>

</head>
<body>
<script type="text/javascript"
    src="jquery-1.8.3.min.js"></script>
<script type="text/javascript"
    src="jszip-utils.js"></script>
<script type="text/javascript"
    src="jszip-utils.min.js"></script>
<script type="text/javascript"
    src="FileSaver.js"></script>
<script type="text/javascript"
    src="jszip.js"></script>

<script type="text/javascript"
    src="downloader.js"></script>
<script type="text/javascript"
    src="helpers.js"></script>
<h3>Please select your files</h3>
<form action="#" id="download_form">
    <ul>
        <li>
            <label>
                <input type="checkbox" data-url="https://github.com/Stuk/jszip/blob/master/index.html" checked />
                Franz Kafka - The Metamorphosis.epub
            </label>
        </li>
        <li>
            <label>
                <input type="checkbox" data-url="https://github.com/Stuk/jszip/blob/master/index.html" checked />
                pygments.css
            </label>
        </li>
        <li>
            <label>
                <input type="checkbox" data-url="https://github.com/Stuk/jszip/blob/master/index.html" />
                jszip.js
            </label>
        </li>
        <li>
            <label>
                <input type="checkbox" data-url="https://github.com/Stuk/jszip/blob/master/index.html" />
                all.zip
            </label>
        </li>
    </ul>

    <button type="submit" class="btn btn-primary">pack them !</button>
</form>

<div class="progress hide" id="progress_bar">
    <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
    </div>
</div>

<p class="hide" id="result"></p>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

更新(解决方案)

脚本声明必须位于表单标记的底部。

<preference name="OverrideUserAgent" value="Mozilla/5.0 My Browser" />