Ho usato $(document).html()
, ma questo ha generato un errore ... c'è un modo per ottenere tutto?Come ottengo l'HTML dell'intera pagina con jQuery?
46
A
risposta
54
Si potrebbe provare:
$("html").html();
Se si desidera catturare anche i tag HMTL li si poteva concatenare al codice HTML in questo modo:
function getPageHTML() {
return "<html>" + $("html").html() + "</html>";
}
2
$("html").html()
otterrebbe tutto, ma il più esterna html tag.
4
60
non dimenticare il tag <html>
può avere attributi troppo. Se vuoi l'intero documento, dovrebbe funzionare.
$('html')[0].outerHTML
È anche banale senza jQuery.
document.documentElement.outerHTML
Se anche voi volete include the doctype, è un po 'più coinvolti.
var getDocTypeAsString = function() {
var node = document.doctype;
return node ? "<!DOCTYPE "
+ node.name
+ (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '')
+ (!node.publicId && node.systemId ? ' SYSTEM' : '')
+ (node.systemId ? ' "' + node.systemId + '"' : '')
+ '>\n' : '';
};
getDocTypeAsString() + document.documentElement.outerHTML
Grazie !! Ha funzionato perfettamente !! –
come ottenere il doctype? –
@Sebastian Non so se è possibile, vedere [questa risposta] (http://stackoverflow.com/questions/3043820/jquery-check-doctype) –