JavaScript / Jquery HTML将DOM结构/页面导出为HTML文件或文本 [英] JavaScript / Jquery HTML Export DOM Structure/Page to HTML File or Text
本文介绍了JavaScript / Jquery HTML将DOM结构/页面导出为HTML文件或文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过DOM修改各种元素属性,然后将该页面保存为html文件。查看源代码并不总是反映dom调整。有没有办法将整个页面写入文件或以其他方式将更新后的源页面放入文件中?
I want to modify through the dom various element properties and then save that page as an html file. View source doesn't always reflect dom adjustments. Is there a way to write the whole page to a file or otherwise get the updated source page into a file?
推荐答案
我在想这应该对ya有用。
I'm thinking this should do the trick for ya.
$('html').html();
JavaScript从浏览器(安全性)运行时无法写入文件。但是你可以把它发送到一个PHP脚本并从那里写入一个文件。例如:
JavaScript can't write files when being ran from a browser (security). But you can send this to a PHP script and write it to a file from there. For example:
$.post('write.php', { dom : $('html').html() });
write.php
file_put_contents('new.html', urldecode($_POST['dom']));
这篇关于JavaScript / Jquery HTML将DOM结构/页面导出为HTML文件或文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文