Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript UIWebView生成关于:追加iframe时的空白请求_Javascript_Dom_Iframe_Uiwebview_Uiwebviewdelegate - Fatal编程技术网

Javascript UIWebView生成关于:追加iframe时的空白请求

Javascript UIWebView生成关于:追加iframe时的空白请求,javascript,dom,iframe,uiwebview,uiwebviewdelegate,Javascript,Dom,Iframe,Uiwebview,Uiwebviewdelegate,这个简单的代码 var-iframe=document.createElement('iframe'); document.documentElement.appendChild(iframe) 通过UIWebView stringByEvaluatingJavascriptFromString注入 使用about:blank生成调用UIWebViewDelegate shouldStartLoadWithRequest。有趣的是,它仍然将mainDocumentURL设置为注入时存在的文档。对

这个简单的代码

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

通过
UIWebView stringByEvaluatingJavascriptFromString注入
使用
about:blank
生成调用
UIWebViewDelegate shouldStartLoadWithRequest
。有趣的是,它仍然将
mainDocumentURL
设置为注入时存在的文档。对我来说,这意味着我不能在任何时候注入这样的代码——重新尝试
shouldStartLoadWithRequest
显然会破坏很多东西。我可以拒绝所有关于以下内容的
about:blank
请求(从
shouldStart…
返回
NO
),互联网上的代码片段可以毫无意义地完成这些任务,但这并不是一个系统性的解决方案


你知道为什么
UIWebView
会有这种混乱和无用的行为吗?

因为你没有在
iframe
上设置
src
属性,默认情况下它会加载
about:blank
。如果要避免这种行为,可以在将
iframe
添加到文档之前使用
iframe.setAttribute
设置一个伪值,然后在
shouldStartLoadWithRequest

Ok中取消伪请求,这样就不会造成混淆,甚至可以对其进行检测以使其有用。有点尴尬:-)