Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView producing about:blank requests when iframe appended

This simple code

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

injected by UIWebView stringByEvaluatingJavascriptFromString produces invocation of UIWebViewDelegate shouldStartLoadWithRequest with about:blank. Which interestingly still has mainDocumentURL set to the document that was there at the time of injection. For me it means that i can't inject such code whenever i want - reentry to shouldStartLoadWithRequest observably breaks a lot of things. I can reject all about:blank requests (returning NO from shouldStart...) and code snippets from the internets do it cluelessly, but it's hardly a systematic solution.

Any ideas why UIWebView has this confusing and useless behavior?

like image 667
Pavel Zdenek Avatar asked May 13 '14 14:05

Pavel Zdenek


1 Answers

Since you don't set a src attribute on your iframe, it will load about:blank by default. If you want to avoid this behavior you could set a dummy value using iframe.setAttribute before you add the iframe to the document and then cancel the dummy request in shouldStartLoadWithRequest.

like image 103
Matthew Gertner Avatar answered Oct 01 '22 12:10

Matthew Gertner