3

I need a java script function that converts the document object of the current loaded page back to it's source text. In firefox it's smth like that:

var doc = document; var str = (new XMLSerializer()).serializeToString(doc); alert(str); 

But i need a cross browser solution. How would this be done?

For example:

<html> <body> <script> alert( asText(document) ); </script> </body> </html> 

would pop up:

<html> <body> <script> alert( asText(document) ); </script> </html> 

how would you implement the 'asText' function?

2 Answers 2

7

Why do not you use document.documentElement.innerHTML?

example

Sign up to request clarification or add additional context in comments.

Comments

0
function sourceText(){ try{ var O= new XMLHttpRequest(); O.open('GET', location.pathname, false); O.send(null); return O.responseText; } catch(er){ return ''; } } 

1 Comment

nice idea, what if the current site was obtained with a POST and got passed some parameters?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.