iOS - UIWebViewDelegate拦截javascript调用 [英] iOS - UIWebViewDelegate intercept javascript calls
问题描述
我正在使用这个过程来允许javascript从我的iPad应用程序调用目标c:
I'm using pretty much the this process oulined here to allow javascript to call objective c from my iPad app:
http://www.stevesaxon.me/posts/2011/window-external-notify-in -ios-uiwebview /
我注入页面的我的javascript代码是:
My javascript code that I'm injecting into the page is:
<script type="text/javascript">;
window.external =
{
'Set_A': function(s) { document.location = 'qms://Set_A?param=' + s; },
'Get_A': function(s) { document.location = 'qms://Get_A'; },
'Set_B': function(s) { document.location = 'qms://Set_B?param=' + s; },
'Get_B': function(s) { document.location = 'qms://Get_B'; },
'Set_C': function(s) { document.location = 'qms://Set_C?param=' + s; },
'Get_C': function(s) { document.location = 'qms://Get_C'; },
'Get_Version': function(s) { document.location = 'qms://Get_Version'; }
};
</script>;
调用上述初始化方法的html代码中的javascript为:
And the javascript in the html code that calls the above method for initialization is:
<html>
<body>
...
<script type="text/javascript">
Get_Version();
Set_A(true);
Set_B(false);
Set_C(true);
<script>
</body>
</html>
在上面的html中,在Objective C中调用的唯一方法是最后一个方法Set_C(true) ;
In the above html the only method that gets called in Objective C is the last method Set_C(true);
谢谢。
推荐答案
所以我用这个博客文章来制作事情有效: http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript/
So I used this blog entry to make things work: http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript/
这篇关于iOS - UIWebViewDelegate拦截javascript调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!