Ionic framework Ionic Android inappbrowser插件-将iframe中的所有链接设置为在系统浏览器中打开

Ionic framework Ionic Android inappbrowser插件-将iframe中的所有链接设置为在系统浏览器中打开,ionic-framework,cordova-plugins,inappbrowser,Ionic Framework,Cordova Plugins,Inappbrowser,如何将iframe中的所有链接设置为在系统web浏览器中打开,而不是在WebView中打开?我正在使用插件 iframe内容 我从中找到了这个解决方案(不是我写的)。 基本上,它声明了一个angular过滤器,将href链接转换为窗口。open使用inappbrowser插件打开链接 var myApp = angular.module('myApp', ['ngSanitize']); myApp.filter('hrefToJS', function ($sce, $sanitize)

如何将iframe中的所有链接设置为在系统web浏览器中打开,而不是在WebView中打开?我正在使用插件


iframe内容

我从中找到了这个解决方案(不是我写的)。 基本上,它声明了一个
angular
过滤器
,将href链接转换为
窗口。open
使用inappbrowser插件打开链接

var myApp = angular.module('myApp', ['ngSanitize']);

myApp.filter('hrefToJS', function ($sce, $sanitize) {
    return function (text) {
        var regex = /href="([\S]+)"/g;
        var newString = $sanitize(text).replace(regex, "onClick=\"window.open('$1', '_blank', 'location=yes')\"");
        return $sce.trustAsHtml(newString);
    }
});

myApp.controller('MyCtrl', function ($scope) {
    $scope.html = "This a link: <a href='https://www.google.com'>Google</a> :)";
    $scope.plaintext = "This is a link: https://www.google.com :) "
});
var myApp=angular.module('myApp',['ngSanitize']);
myApp.filter('hrefToJS',函数($sce,$sanitize){
返回函数(文本){
var regex=/href=“([\S]+)”/g;
var newString=$sanitize(text).replace(regex,“onClick=\”window.open('1','u blank','location=yes')\);
返回$sce.trustAsHtml(newString);
}
});
myApp.controller('MyCtrl',函数($scope){
$scope.html=“这是一个链接::)”;
$scope.plaintext=“这是一个链接:https://www.google.com :) "
});
HTML模板中的用法:

<div ng-app="myApp">
    <div ng-controller="MyCtrl">
         <h1>Before</h1>
        <p ng-bind-html="html"></p>
        <p ng-bind-html="plaintext"></p>
         <h1>After</h1>
        <p ng-bind-html="html | hrefToJS"></p>
        <p ng-bind-html="plaintext | linky | hrefToJS"></p>
    </div>
</div>

之前

之后


我可以将此应用于iframe吗?我可以看到它如何与常规链接一起工作,但不确定如何将其应用于iframe内的链接。
<div ng-app="myApp">
    <div ng-controller="MyCtrl">
         <h1>Before</h1>
        <p ng-bind-html="html"></p>
        <p ng-bind-html="plaintext"></p>
         <h1>After</h1>
        <p ng-bind-html="html | hrefToJS"></p>
        <p ng-bind-html="plaintext | linky | hrefToJS"></p>
    </div>
</div>