Javascript iphone webview和iframe问题
我正在为iphone应用程序创建一个“web加载器”。html文件与iphone应用程序捆绑在一起,并加载到webview中。在Javascript iphone webview和iframe问题,javascript,iphone,iframe,webview,Javascript,Iphone,Iframe,Webview,我正在为iphone应用程序创建一个“web加载器”。html文件与iphone应用程序捆绑在一起,并加载到webview中。在webviewdiffinishload中,我使用stringByEvaluatingJavascriptFromString执行一个javascript函数,该函数创建一个iframe,等待它加载,然后将它转换到屏幕上。似乎创建iframe的过程会不断地反复调用webViewDidFinishLoad。有没有人遇到过这个问题,或者有没有提示我如何通过javascrip
webviewdiffinishload
中,我使用stringByEvaluatingJavascriptFromString
执行一个javascript函数,该函数创建一个iframe,等待它加载,然后将它转换到屏幕上。似乎创建iframe的过程会不断地反复调用webViewDidFinishLoad
。有没有人遇到过这个问题,或者有没有提示我如何通过javascript创建iframe而不触发这个bug
HTML文件js代码如下所示:
var ifrm;
function load(url) {
ifrm = document.createElement("IFRAME");
ifrm.setAttribute("src", url);
ifrm.style.width = "100%";
ifrm.style.height = "100%";
ifrm.style.display = "none";
ifrm.onload = function () {
document.getElementById('loading').style.display = 'none';
ifrm.style.display = '';
}
document.body.appendChild(ifrm);
}
我不太喜欢原生的iphone应用程序。但是在一个普通页面中,你可以做相反的事情 加载
iframe
而不加载onload
事件,并在加载文档的正文
末尾的脚本
标记中调用父级,如:
<body>
...
<script>
//the document is loaded
//call a function in the parent page
parent.appObj.iframeLoadedCallback(window);
</script>
</body>
...
//文档已加载
//在父页面中调用函数
parent.appObj.iframeloaddedcallback(窗口);
我的问题是,在javascript中创建的iframe导致第二个webViewDidFinishLoad方法触发。我在这个方法中错误地再次调用了我的js函数,这将导致创建一个新的iframe并导致循环行为。我只是忽略了这个方法的第二个调用,一切都按预期进行