I'm currently trying to get the contents of an iframe's body without any mangling of content by the browser.
I could do it by including the content in a textarea, however i want to avoid that.
using .innerHTML results in special characters such as "<" ">" and "&" being converted to "<", ">", and "&" respectively.
To test, build an html file containing:
- {
- "id": 5,
- "testtext":"I am > than this & < that",
- "html":"<div>\"worky\"</div>"
- }
and then build a test file to work from:
- <!doctype html>
- <html>
- <head>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- </head>
- <body>
- <iframe id="myIframe" name="myIframe" src="test.html"></iframe><br />
- Result:<br />
- <textarea id='result'></textarea>
- <script>
- $("#myIframe").load(function(){
- var iframeBody = window.frames.myIframe.document
- .getElementsByTagName("body")[0];
- $("#result").val(iframeBody.innerHTML);
- });
- </script>
- </body>
- </html>
in the textarea you should see the text json response, however the special characters get replaced.
-- Kevin