After setting an control's location to some site. How could I then take a peek at the associated HTML? I notice that as soon as I set Location, htmlText becomes null and vice-versa... So how would one go about looking at the HTML displayed in the control in TEXT form?
They sure don't make this easy, but the trick is to use the DOM.
My HTML control is named 'html'
<mx:HTML id="html" location="http://www.googolflex.com"
width="100%" height="100%" />
The DOM is contained within in the HTML component's HTMLLoader, which is conveniently called 'htmlLoader'.
var o : Object = html.htmlLoader.window.document.getElementsByTagName("html")[0];
trace( o.textContent );
trace( o.innerText );
trace( o.innerHTML );
I'm not a JavaScript expert, but you essentially have the DOM exposed to you through html.htmlLoader.window. Aside from being a not-so-convenient way to view the source, this allows you to do a lot of JavaScript-esque tasks via ActionScript.
This help document lead me to this solution: Accessing DOM and JavaScript objects from ActionScript
I always forget how to do this, and i've actually just been searching how to do it again. Found this snippet in an old project of mine:
HTMLComponent.domWindow.document.documentElement.outerHTML
Though i am not sure if this represents modifications made by javascript.
be sure to only trace this on a complete event from the HTML component (unless you know the page has finished loading).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With