How do I get the entire page's HTML with jQuery?

后端 未结 5 732
有刺的猬
有刺的猬 2020-11-27 04:45

I used $(document).html(), but that threw an error... is there a way to get everything?

5条回答
  •  天命终不由人
    2020-11-27 05:01

    No need to lean on jQuery. The best and simplest approach is to use

    new XMLSerializer().serializeToString(document)
    

    which will always give you the contents of the entire page including DOCTYPE tag, and it is supported in all modern browsers: https://caniuse.com/#feat=xml-serializer

提交回复
热议问题