2016-01-23 30 views
2

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

<ion-view style="" title="iframe"> 
<ion-content class="has-header" overflow-scroll="true" padding="true"> 
    <div style="" class="list card"> 
     <div class="item item-divider-android">iframe content</div> 
     <div class="item item-body-android"> 
      <div style=""> 
       <center> 
<iframe src='{{trustSrc(iframe.src)}}' frameborder="0" width="100%" height="500" scrolling="yes"></iframe></center> 
       </div> 
      </div> 
     </div> 
    </ion-content> 

回答

1

我发现在gist(我没写)这个解决方案。 基本上它声明的angularfilter是HREF链接转换成window.open打开你的HTML模板使用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 :) " 
}); 

用法链接:

<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> 
+0

我可以应用此的iframe?我可以看到它如何与常规链接一起工作,但不知道如何将其应用于iframe中的链接。 – student

相关问题