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?
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
.
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