1

I am trying to get the html source of a website including all the styles of the elements set by the css. So basically the rendered html of the page, such that if an element is hidden it has style = display:none

When using the functions below style attributes added by the css are not included in the string.

document.getElementsByTagName('html')[0].innerHTML;

or

inDocument.documentElement.innerHTML;

Is there a way to include the css attributes?

Thanks, James

Levon
  • 138,105
  • 33
  • 200
  • 191
James
  • 589
  • 1
  • 6
  • 15
  • I'm actually passing the html string back to java so iframes aren't an option – James Jun 07 '12 at 05:02
  • Sorry, actually posted an answer and then checked this.. This may be of some help http://stackoverflow.com/questions/4781410/jquery-how-to-get-all-styles-css-defined-within-internal-external-document-w – verisimilitude Jun 07 '12 at 05:24

2 Answers2

1

This will help you jQuery CSS plugin that returns computed style of element to pseudo clone that element?

Also check the jQuery clone function mentioned here http://api.jquery.com/clone/

Community
  • 1
  • 1
kiranvj
  • 32,342
  • 7
  • 71
  • 76
  • So I could run that as I parse the elements and add them to a string? Then return the string. – James Jun 07 '12 at 05:04
  • >>add them to a string Not sure. But you can add them to an object, because clone() returns a jQuery object. – kiranvj Jun 07 '12 at 05:09
1

I don't think jQuery is necessary for fetching the HTML Source. Just use

document.documentElement.outerHTML

This will include the CSS attributes as well.

verisimilitude
  • 5,077
  • 3
  • 30
  • 35
  • Will it include computed styles also? – kiranvj Jun 07 '12 at 05:22
  • Sorry, actually posted an answer and then checked this.. This may be of some help http://stackoverflow.com/questions/4781410/jquery-how-to-get-all-styles-css-defined-within-internal-external-document-w – verisimilitude Jun 07 '12 at 05:27