How do you access Content of an Iframe using GWT?
I have a HiddenIframe that i created in GWT which gets response from a post. OnBrowsewerevent() i try to introspect the contents of Iframe for a error code or success.
When i access the Iframe via GWT, I can access it but innerHTML method always null
I write a JSNI method
private native String getMessage()/*-{
var e = document.getElementById('my_iframe');
var html = e.contentWindow.document.body.innerHTML;
return html
}-*/;
I always get e as null as Ge开发者_开发百科telementbyID is returning null, When i introspect HTMLusing firebug i can see the Iframe with the ID. What is the best way to solve the problem?
You need to use the GWT specific $doc
variable, instead of document
. From the GWT JSNI documentation:
When accessing the browser's window and document objects from JSNI, you must reference them as $wnd and $doc, respectively. Your compiled script runs in a nested frame, and $wnd and $doc are automatically initialized to correctly refer to the host page's window and document.
精彩评论