我无法触发 cordova inAppBrowser 打开 URL

I am unable to trigger cordova inAppBrowser to open URLs

在我的应用程序中,我在转发器中有一个指令,该指令向用户显示 URL。

我的代码如下:

var onDeviceReady;

onDeviceReady = function() {
  console.log("this was called");
  return window.open = cordova.InAppBrowser.open;
};

document.addEventListener('deviceready', onDeviceReady, false);

并在 html

<a href="#" on-click="window.open('{{data.url}}', '_blank', 'location=yes');">{{data.url}}</a>

当我尝试在 android 设备上打开应用程序时,控制台消息打印正确(意味着应该调用该函数)但所有 url 根本没有打开。

我的索引文件看起来像这样(万一有用):

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <meta http-equiv="Content-Security-Policy"
          content="default-src * gap://ready file: data:; style-src 'self' 'unsafe-inline' *; font-src 'self' data: https://fonts.gstatic.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' *">
    <title></title>
    <link href="css/bower.css" rel="stylesheet" id="bower-css">
    <link href="css/style.css" rel="stylesheet" id="style-css">
</head>

<body ng-app="myApp" ng-strict-di>
   <ion-nav-view class="slide-left-right" animation="slide-left-right"></ion-nav-view>

<script src="js/bower.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
<script src="js/templates.js"></script>
</body>
</html>

我目前安装的插件如下:

cordova-plugin-inappbrowser 1.7.1 "InAppBrowser"

cordova-plugin-whitelist 1.3.2 "Whitelist"

问题是 on-click

您可以使用 html onclick,或 angular ng-clickon-tap,但 on-click 不存在

此外,对于 onDeviceReady,您不需要 return,但这并不妨碍它正常工作。

最后我终于成功了。

基本上,我替换了

ng-click="window.open('{{data.url}}', '_blank', 'location=yes');">

具有函数:

ng-click="openRUL({{data.url}})">

然后函数如下所示:

$scope.openURL = function (url){
  window.open(url, '_blank', 'location=yes')
}

现在一切正常。