How do I get the HTML source from the page?

前端 未结 5 468
谎友^
谎友^ 2020-11-29 07:37

Is there a way to access the page HTML source code using javascript?

I know that I can use document.body.innerHTML but it contains only the code inside

5条回答
  •  被撕碎了的回忆
    2020-11-29 08:00

    This can be done in a one-liner using XMLSerializer.

    var generatedSource = new XMLSerializer().serializeToString(document);
    

    Which gives String

    
    
    html - javascript page source code - Stack Overflow
    ...
    

提交回复
热议问题