Get the whole document's html with JavaScript/JQuery

前端 未结 8 1283
无人及你
无人及你 2021-02-14 16:54

I know it\'s already discussed here, but there were no solution to get the whole document (including doctype).

$(document).html(); returns null

8条回答
  •  轮回少年
    2021-02-14 17:19

    I don't think there is a direct access to the whole document (including the doctype), but this works :

    $.get(document.location, function(html) {
        // use html (which is the complete source code, including the doctype)
    });
    

提交回复
热议问题