从按钮将页面另存为html文件

时间:2018-07-23 17:37:58

标签: javascript html

我一直在这些论坛上四处寻找可以直接下载HTML页面的代码(例如,从其他按钮添加了元素,以及div中的所有内容),以便可以再次使用数据仍然存在。我一生都找不到下载该页面的任何内容。下面是我真正用来保存html文档的最接近的文档,即使(显然)该文档仅显示所写的文本。我可以对其进行编辑以使其封装整个页面吗? 以很少的经验我只能道歉。

:compileDebugJavaWithJavac
/media/ivan/SharedPartition/Trabajo/AnimaEdu/animaedu-mobile/platforms/android/src/com/pushwoosh/plugin/pushnotifications/PushNotifications.java:888: error: lambda expressions are not supported in -source 1.6

            mainHandler.post(() -> webView.loadUrl("javascript:"+ url));
                                ^
  (use -source 8 or higher to enable lambda expressions)
1 error
 FAILED
27 actionable tasks: 1 executed, 26 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 9s
(node:18368) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: /media/ivan/SharedPartition/Trabajo/AnimaEdu/animaedu-mobile/platforms/android/gradlew: Command failed with exit code 1 Error output:
/media/ivan/SharedPartition/Trabajo/AnimaEdu/animaedu-mobile/platforms/android/src/com/pushwoosh/plugin/pushnotifications/PushNotifications.java:888: error: lambda expressions are not supported in -source 1.6
            mainHandler.post(() -> webView.loadUrl("javascript:"+ url));
                                ^
  (use -source 8 or higher to enable lambda expressions)
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 9s

2 个答案:

答案 0 :(得分:0)

一种解决方案是FileSaver.js

遵循该页面上的示例,并为您的Blob使用document.innerHTML(我用过的东西)实际上,我忘记了是否不包括标题。如果是这样,我对此有一个解决方案(也在StackOverflow上),但我在本地没有代码可以查看如何解决此问题(如果确实这样做,则必须解决)

答案 1 :(得分:0)

您可以尝试

<a href ="#" id="donwload-link" onClick="myFunction()">download html content</a>

<script>
function myFunction() {
  var content = document.documentElement.innerHTML;
  download(content, "index", "txt")

}
function download(content, fileName, fileType) {
  var link = document.getElementById("donwload-link");
  var file = new Blob([content], {type: fileType});
  var donwloadFile = fileName + "." + fileType;
  link.href = URL.createObjectURL(file);
  link.download = donwloadFile
}
</script>

https://jsfiddle.net/a9oLw1zv/13/