2009-06-11 8 views

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>"; 
} 
+0

Grazie !! Ha funzionato perfettamente !! –

+0

come ottenere il doctype? –

+0

@Sebastian Non so se è possibile, vedere [questa risposta] (http://stackoverflow.com/questions/3043820/jquery-check-doctype) –

2

$("html").html() otterrebbe tutto, ma il più esterna html tag.

4

Usa:

document.body.innerHTML 
+2

Se si desidera utilizzare l'intero documento html: 'window.document.innerHTML' – simo

+2

@simo:' document' non ha una proprietà 'innerHTML' in nessun browser che utilizzo ancora. – cHao

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 
Problemi correlati