【问题标题】:how to get loaded html download file with javascript/jquery如何使用 javascript/jquery 获取加载的 html 下载文件
【发布时间】:2016-05-25 03:50:27
【问题描述】:

我正在尝试使用这个库https://github.com/hrikrishnankr/Pdf2Html 上传pdf并下载html文件。我已经能够使用

成功下载 html 文件
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/html;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none'; 
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}

然后我有这个从查看器获取 html

var data=document.getElementById("viewer").innerHTML;

并在单击按钮下载按钮时运行该函数

<button id="download" class="toolbarButton download hiddenMediumView" title="Download" tabindex="34" data-l10n-id="download"
            onclick="downloadhtml()">

function downloadhtml() {

var data=document.getElementById("viewer").innerHTML;
download('file.html', data);
}

但我得到的文件主要是加载的空 div 容器

<div class="loadingIcon"></div>

据说它应该已经内置了pdf2html转换功能。加载完成后如何在查看器中获取html并将其下载到文件中?

【问题讨论】:

    标签: javascript jquery html pdf


    【解决方案1】:

    使用 JQuery 可以这样做。

    $('<form />', { action: downloadURL, "id": "downloadForm", method: 'GET', target: '_blank', html: '<input type="hidden" id="file" name="file" value="' + fileURL + '" />'}).appendTo(document.body).submit();
    

    或者使用简单的 Javascript 首先您需要创建表单元素,然后在操作中提供下载 url 并提交。

    【讨论】:

    • 不,您必须滚动才能加载页面,这与此无关
    猜你喜欢
    • 1970-01-01
    • 2021-12-18
    • 2017-01-13
    • 2013-02-28
    • 1970-01-01
    • 2022-01-05
    • 2018-11-02
    • 1970-01-01
    相关资源
    最近更新 更多