Can I get all the page code using innerHTML
? Or with something else.
|
5 answers
window.onload = function(){ alert(document.documentElement.innerHTML); };
When everything is loaded then get and not during processing like some of the other answers given here, but generally google onDOMLoad so as not to wait for the download of pictures, etc.
|
$("html").html();
or pure js
document.documentElement.innerHTML
- on pure js, without any jquery - shol
- updated the answer - Maksym Prus
- I tried it, it does not work - shol
- Everything works fine, what does not work for you? - Maksym Prus
- var cod = document.documentElement.innerHTML; the cod variable in me contains the first element between the tags <head> - shol
|
var doc = document || window.document; alert(doc.body.innerHTML);
- This if dom need - Ilyas
- @ilyas and you know when your code is executed? - Rules
- Well, he didn’t write when he needed, of course, it’s more correct to call him when body onLoad, and so I threw a stupid piece of code that displays the dom pages and that's it. - Ilyas
- ... so here it is executed
onLoad
(i.e. window.onload) You chose this at the top left, but if you selectload
in the head, the code will not work correctly, so the vehicle must first know when its code is executed and then such questions will disappear by themselves imho ... - Rules - I will take into account the next time, I estimated a person in the course that there is nothing to display if the document was not loaded. - Ilyas
|
What about doctype
? If a person needs to copy the entire page, then doctype
also needed.
var node = document.doctype; var doctypeHtml = "<!DOCTYPE " + node.name + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '') + (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>'; var result = doctypeHtml + document.documentElement.outerHTML
code borrowed from enSO
|
what have the body
? Between
<script type="text/javascript"> var html = document.documentElement.innerHTML; alert(html); </script>
need to post. Preferably in the head
tag.
- And so it is clear that the scripts need to be placed in the
<script/>
. And at the expense of the head, not a fact, if there are many elements in the document, then all of them (nodes) will have time to load - Maksym Prus
|