Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.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 调用UIWebViewDelegate方法";“当我想要的时候”;_Javascript_Iphone_Cocoa Touch_Uiwebview - Fatal编程技术网

Javascript 调用UIWebViewDelegate方法";“当我想要的时候”;

Javascript 调用UIWebViewDelegate方法";“当我想要的时候”;,javascript,iphone,cocoa-touch,uiwebview,Javascript,Iphone,Cocoa Touch,Uiwebview,我正在使用webView:shouldStartLoadWithRequest:navigationType方法从JavaScript调用我的Objective-C代码,该代码运行正常。问题是,只有在重新加载Web视图时才会调用此方法。我希望能够“随时”发送消息。可能吗 具体来说,我想使用document.location=“myapp:”+“customerAdded:”+“YES”只要我愿意。我的代码只有在使用GoogleAPIv3绘制地图时才会执行 是否可以重新加载“不可见”帧以调用委托方

我正在使用
webView:shouldStartLoadWithRequest:navigationType
方法从JavaScript调用我的Objective-C代码,该代码运行正常。问题是,只有在重新加载Web视图时才会调用此方法。我希望能够“随时”发送消息。可能吗

具体来说,我想使用
document.location=“myapp:”+“customerAdded:”+“YES”只要我愿意。我的代码只有在使用GoogleAPIv3绘制地图时才会执行


是否可以重新加载“不可见”帧以调用委托方法?

webView:shouldStartLoadWithRequest:navigationType:
仅应在重新加载web视图时调用,这就是此委托的目的。您可以使用
NSNotificationCenter
调用重新加载Web视图的方法。

试试这个,对我来说很好

function invokeObjectiveC() {
    var iframe = document.createElement("IFRAME");
    iframe.setAttribute(your stuff here);
    document.documentElement.appendChild(iframe);
    iframe.parentNode.removeChild(iframe);
    iframe = null;
}

它必须重新加载整个页面才能调用代理吗?是的,您不能以任何方式加载网页的一部分,因此此方法触发
webView:shouldStartLoadWithRequest:navigationType