javascript - 来自 InAppBrowser 的返回变量

标签 javascript jquery html cordova

我使用的是 cordova 2.5.0,我在使用 InAppBrowser 与我的应用程序通信新窗口时遇到问题。可以将信息从使用 InAppBrowser 插件打开的页面发送回我的 cordova 应用程序。

最佳答案

这曾经有点复杂(如 pollingcustom urls ),但自从在 AppBrowser 3.0.0 中您可以将 AllowedSchemescustomscheme 事件一起使用。这还没有记录,但可以按如下方式使用。

到你的config.xml,添加

<preference name="AllowedSchemes" value="myscheme" />

在您的 Cordova 应用程序中使用以下代码:

function onCustomScheme(e) {
  if (e.url.match(/^myscheme:\/\/message\b/)) {
     var q = parseQueryString(e.url);
     console.log("Got foo message: " + q.text);
  }
}

url = "https://my.example.com/";
app = cordova.InAppBrowser.open(url, "_blank");
app.addEventListener("customscheme", onCustomScheme, false);

然后从在 inAppBrowser 中打开的网站,您可以嵌入这样的链接,如果您关注它,它会在控制台中显示消息hi there

<a href="myscheme://message?text=hi+there">Test</a>

这不适用于 Cordova 2.5(看起来您至少需要 3.1),但由于 8 现已推出,无论如何升级可能是个好主意。

关于javascript - 来自 InAppBrowser 的返回变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16012941/

相关文章:

html - Bootstrap : Set table column width for small devices

javascript - 按对象名称对对象数组进行排序 Typescript

php - 数据库解锁后 ajax 多次触发

javascript - 如何使用 Javascript 对 HTML 表单进行错误检查,包括验证字段是否填写正确?

javascript - 限制允许选中的复选框数量

javascript - 将输入字符串与文本/元素匹配并突出显示 react 性

html - html中的div和文本框

html - 在图像顶部绘制垂直线

javascript - 从用户控件内部关闭 jQuery 对话框

javascript - 使用 jQuery 从 iFrame 操作主框架?