javascript - scrape parent page html from iframe -
i have iframe used generate pdf parent page. pdf maker (abcpdf) requires html file converts.
what @ present scrape parent's html using:
var temp; temp=parent.document.body.parentnode.innerhtml;
then use form in iframe submit server massaged remove things iframe sections before being saved temporary html file pdf maker.
however resulting html code mangled, <body>
instead of <body>
etc , quotes around ids removed etc.
is there better way grab html?
the reason don't regenerate page html parent page complex report. contains various controls allow user show/hide sections or sort rows in tables. html has reflect user customisations.
thanks
as david mentioned, using innerhtml
, you're pretty @ browser's mercy. if want have control on serialization, walk dom of parent document yourself, appending string representation of nodes buffer. take longer , involve more code, result in full control on output.
something (pseudocode):
function serializeattributes(node, buffer) { (attribute in node.attributes) { buffer.append(' ' + attribute.name + '="' + attribute.value + '"'); } } function serializechildren(node, buffer) { (child in node.childnodes) { if (child text node) { buffer.append(child.value); } else if (child element) { // can add checks avoid going iframes, etc. serializeelement(child, buffer); } } } function serizalizeelement(node, buffer) { buffer.append('<' + node.tagname); serializeattributes(node, buffer); if (node.haschildren) { buffer.append('>'); serializechildren(node, buffer); buffer.append('</' + node.tagname + '>'); } else { buffer.append('\>'); } } serializenode(window.parent.document);
Comments
Post a Comment