JavaScript / JQuery HTML Export DOM / page structure to HTML file or text

I want to change various properties of the element through dom, and then save this page as an html file. Viewing the source does not always reflect home settings. Is there a way to write the entire page to a file or otherwise get the updated source page in a file?

+4
source share
2 answers

I think this should do the trick for you.

$('html').html(); 

JavaScript cannot write files when launched from the browser (security). But you can send this to a PHP script and write it to a file from there. For instance:

 $.post('write.php', { dom : $('html').html() }); 

write.php

 file_put_contents('new.html', urldecode($_POST['dom'])); 
+6
source

In new browsers (IE 10, FF 20, Chrome 26, Safari 6, Opera 15), you can create a Blob and save it to a file using window.URL.createObjectURL .

Demo , Link :

 objectURL = window.URL.createObjectURL(blob); 
  • Where Blob is a File or Blob object to create a URL object for.
  • objectURL is the generated URL of the object. All contents of the specified file are represented by the text of the URL. Then it can be used in window.open .

Example a Blob :

 var parts = ["<p class=\"paragraph\"><a id=\"link\">hey!<\/a><\/p>"]; new Blob(parts, { "type" : "text\/html" }); 

To display the current Blob in Chrome, follow these steps in the address bar:

 chrome://blob-internals 
+6
source

All Articles