UIWebView creating around: empty requests when adding iframe

This simple code

var iframe = document.createElement('iframe'); document.documentElement.appendChild(iframe);

the entered UIWebView stringByEvaluatingJavascriptFromString calls the UIWebViewDelegate shouldStartLoadWithRequest using about:blank . Interestingly, mainDocumentURL set in the document that was there during the injection. For me, this means that I cannot enter such code whenever I want - re-inclusion in shouldStartLoadWithRequest , as a rule, breaks a lot of things. I can reject all about:blank requests (return NO from shouldStart... ), and code snippets from the Internet make this elusive, but this is hardly a systematic solution.

Any ideas why UIWebView has this confusing and useless behavior?

+6
source share
1 answer

Since you do not set the src attribute on the iframe , it will load about:blank by default. If you want to avoid this behavior, you can set the dummy value with iframe.setAttribute before adding the iframe to the document and then cancel the dummy request in shouldStartLoadWithRequest .

+6
source

All Articles