ef调用触发shouldStartLoadWithRequest

ef调用触发shouldStartLoadWithRequest

本文介绍了使用多个window.location.href调用触发shouldStartLoadWithRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过UIWebView的shouldStartLoadWithRequest方法将多个内容从UIWebView内的网页传递回我的iPhone应用程序。

Im trying to pass multiple things from a webpage inside a UIWebView back to my iPhone app via the shouldStartLoadWithRequest method of the UIWebView.

基本上我的网页调用window.location .href =command:// foo = bar我可以在我的应用程序中拦截它没问题。现在,如果我创建一个循环并立即执行多个window.location.href调用,那么shouldStartLoadWithRequest似乎只会被调用一次,并且它获得的调用是循环结束时window.location.href的最后一次触发。

Basically my webpage calls window.location.href = "command://foo=bar" and i am able to intercept that in my app no problem. Now if i create a loop and do multiple window.location.href calls at once, then shouldStartLoadWithRequest only appears to get called on once and the call it gets is the very last firing of window.location.href at the end of the loop.

同样的事情发生在Android的webview上,只有最后一个window.location.href得到处理。

The same thing happens with the webview for Android, only the last window.location.href gets processed.

推荐答案

iFrame = document.createElement("IFRAME");
iFrame.setAttribute("src", "command://foo=bar");
document.body.appendChild(iFrame);
iFrame.parentNode.removeChild(iFrame);
iFrame = null;

所以这会创建一个iframe,将其源代码设置为一个试图传递给app的命令,然后一旦它附加到主体shouldStartLoadWithRequest被调用,那么我们从主体中删除iframe,并将其设置为null以释放内存。

So this creates an iframe, sets its source to a command im trying to pass to the app, then as soon as its appended to the body shouldStartLoadWithRequest gets called, then we remove the iframe from the body, and set it to null to free up the memory.

我还使用shouldOverrideUrlLoading在Android网页视图上对此进行了测试,并且它也正常运行!

I also tested this on an Android webview using shouldOverrideUrlLoading and it also worked properly!

这篇关于使用多个window.location.href调用触发shouldStartLoadWithRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 15:16