how to handle iframes/frames dom in the iphone uiwebview
in
(void) webViewDidFinishLoad: (UIWebView*)webView
I inject some javascript to handle the iframes. e.g.
stringByEvaluatingJavaScriptFromString:
@"try {
var document = window.document.getElementsByTagName开发者_运维问答('iframe')[0].contentWindow.document.getElementsByTagName('frame');
} catch (e) {
alert (e.message);
}"
It tells me the iframes document is undefined. Actually I have tried to print all the properties of contentWindow of iframe, but it's totally empty.
I know the webViewDidFinishLoad may be called several times for each frame load. But I can never get the iframe document. I thought there should be at least once all the iframes are ready.
Could someone please tell me how to get the iframe document to process the dom in the uiwebview?
Thanks
You should use postMessage Api in order to access code inside cross domain iframe. Please see here for further details about how to implement this.
精彩评论