【问题标题】:How can I download the current DOM with HTML or JavaScript?如何使用 HTML 或 JavaScript 下载当前的 DOM?
【发布时间】:2018-07-23 18:11:23
【问题描述】:

我创建了一个 HTML 文件,稍后我通过单击一个按钮使用 JavaScript 对其进行修改。该按钮在按下时基本上会更改 div 的内容。

现在,我在该 div 中新创建的内容中添加了一个按钮,我希望它提示“另存为”窗口 (ctrl + s) 或直接下载它。

我被限制使用任何框架或库,如 jquery。 必须是纯 html 或 javascript。

要明确:<a> 中的“下载”属性会下载对我不利的原始 DOM。

【问题讨论】:

标签: javascript html dom ecmascript-6


【解决方案1】:

javascript document.documentElement 返回根元素中的所有元素。只是不添加 html 标签或 doctype declerations。

<html>

<head>
    <title>Haha</title>
    <script>
        function test(){console.log("<html>" + document.documentElement + "</html>")}
    </script>
</head>
<body onload="test()">
    <div><p>Hi!</p></div>
</body>
</html>

【讨论】:

    猜你喜欢
    • 2021-11-01
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 2016-04-09
    • 1970-01-01
    • 2013-04-11
    • 2011-01-08
    • 2011-11-08
    相关资源
    最近更新 更多