【问题标题】:Cordova InAppBrowser EventListeners not working on iosCordova InAppBrowser EventListeners 无法在 ios 上运行
【发布时间】:2017-02-04 14:01:12
【问题描述】:

在 iphone 7 设备或模拟器上运行时,inappbrowser 成功打开,但从不调用事件监听器。下面的代码在 android 上运行良好。 我正在使用cordova 6.5.0,inappbrowser 插件是1.6.1 版。我目前正在使用 mac osx 10.12.2。

function redirect () {
  if (isloggedin){
    navigator.notification.alert("You are already logged in");
  } else {
    var url = "https://connect.stripe.com/oauth/authorize?response_type=code&client_id=CLIENT_ID&scope=read_write";
    var target = "_system";
    var options = "location=yes, hidden=no, clearcache=yes";
    browserRef.addEventListener('loadstart', function(event) {
      if ((event.url).indexOf("https://example.com") !== -1) {
        var redirectedURI = event.url;
        registerUser(redirectedURI);
        browserRef.close();
      }
    });
  }
}

这是带有info about browserRef. 的导航器通知的图像 我非常乐意提供更多信息,例如我的 config.xml。 非常感谢任何帮助,谢谢。

编辑:每当我尝试在重定向函数末尾添加 browserRef.close() 时,我都会从 xcode 中收到错误“IAB.close() 已调用但它已经关闭”。我也试过 window.open() 没有任何成功。

编辑 2:单击此按钮时调用重定向功能

<a href="#" onClick="redirect();">Online Payments</a>

【问题讨论】:

    标签: javascript ios cordova cordova-plugins inappbrowser


    【解决方案1】:

    好的,所以在尝试了几件事之后,这对我有用。我测试了在不同目标上触发所有四个可能的 inappbrowser 事件。这些事件会回火的唯一目标是“_blank”。

    browserRef.addEventListener('loadstart', function(event) { navigator.notification.alert(event, event.url); });
    browserRef.addEventListener('loadstop', function(event) { navigator.notification.alert(event); });
    browserRef.addEventListener('loaderror', function(event) { navigator.notification.alert(event, event.code, event.message); });
    browserRef.addEventListener('exit', function(event) { navigator.notification.alert("exit"); });
    

    我注意到的另一件事:由于某种原因,“loadstart”只能在“_self”上运行。

    虽然我已经解决了这个问题,但如果有人能提供一些关于为什么会发生这种情况的见解,我很乐意提供有关我的代码/构建的更多详细信息。

    【讨论】:

    • 我遇到了同样的问题,发现了同样的行为,关于这个话题有什么进展吗?
    • @Orion390 不是真的,对不起。希望你能弄清楚。
    • 结束了另一种方法,而不是使用 inAppBrowser,我将网站放在科尔多瓦内的 iframe 中,这样在显示网站时一切正常(但要注意很多其他的东西,比如您网站的 X-Frame-Options),希望对某人有所帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多