Is there a way to use jQuery.html() and not loose the scripts and styles? or any other non-jQuery way?
I’m trying to output the full HTML of the page the user is on. Is this even possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That isn’t my experience (see below). In practice, you have to be aware that what you get back by querying the DOM for HTML strings is always going to be the interpreted HTML, not the original, and there will be quirks (for instance, on IE all the HTML tag names are IN UPPER CASE). This is because jQuery’s
htmlfunction relies on the browser’sinnerHTMLproperty, which varies slightly browser to browser. But the demo below includes both style and script tags on Chrome 4, IE7, and Firefox 3.6; I haven’t tried others, but I would expect them to be okay.If you want to get the content of externally-linked pages as well as the inline content, you will naturally have to parse the result and follow the
src(onscripts),href(onlinks that haverel= “stylesheet”), etc…Demo: