javascript - iOS - UIWebViewDelegate 拦截 javascript 调用

标签 javascript ios uiwebviewdelegate

我几乎使用了这里概述的这个过程来允许 javascript 从我的 iPad 应用程序调用 Objective C:

http://www.stevesaxon.me/posts/2011/window-external-notify-in-ios-uiwebview/

我要注入(inject)到页面中的 JavaScript 代码是:

<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为:

<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);

谢谢。

最佳答案

关于javascript - iOS - UIWebViewDelegate 拦截 javascript 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13254751/

相关文章:

ios - 如何知道 UIWebView 何时被用户触摸

objective-c - 如何获取 HTTP header

javascript - 将 React 与工具创建的 SVG 一起使用

ios - 使用纯色背景使导航栏不透明

ios - UI 导航栏图像标题

ios - 管理通过 HTML [iOS] 生成的 PDF 文档的分页符

javascript - 发送邮件时$_POST有时为空

javascript - 水平映射数组图像元素

javascript - 在 icontab 中加载动态内容

ios - 在另一个 View Controller 中设置 UIImageView