1

For instance, say I have the HTML page index.html. It has a javascript function someFn() (upon onclick) that needs to obtain the entire contents of this page (which also has text fields that are modified by the user. (So as a result, the page contents will be modified from the original content.) Eventually, this someFn() will try to obtain the entire contents of the page in a variable. This variable is then passed on to a PHP script in another file that does the required work. Alternatively, it may output it to a file which is read by the aforementioned PHP script.

The only problem is how the JS function will obtain the page contents in a variable. jQuery alternatives are welcome as long as they don't mess with the workflow of data shown above.

1 Answers1

3

Try using XMLSerializer.serializeToString() Get DocType of an HTML as string with Javascript to retrieve document.doctype as string , document.documentElement.outerHTML to retrieve html of root element of document

   var html =  new XMLSerializer().serializeToString(document.doctype) 
               + document.documentElement.outerHTML;
Community
  • 1
  • 1
guest271314
  • 1
  • 15
  • 104
  • 177