代码之家  ›  专栏  ›  技术社区  ›  trentclowater

Angular Js和Trigger.io-无法在iOS上运行的Android上关注链接

  •  7
  • trentclowater  · 技术社区  · 13 年前

    我正在使用AngularJS和Trigger.io开发iOS和Android的移动应用程序。

    当我尝试打开如下链接时:

    <a ng-href="#/offers/{{featured_offer.Id}}"></a>
    

    它在iOS上运行得很好,但在Android上,我在触发控制台中收到了这条消息,链接无法导航到:

    [WARNING] Attempted to open a URL which could not be handled: unsafe:content://io.trigger.forge722b6464a0e211e2ba9d12313d00dc45/src/index.html#/offers/8
    

    我如何才能让它在Android中像在iOS中一样工作?

    3 回复  |  直到 13 年前
        1
  •  9
  •   Connorhd    13 年前

    看起来Angular添加了不安全的内容:对于它不识别的url方案,我认为你想包括以下内容:

    app.config(function($compileProvider){
      $compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel|content):/);
    });
    

    它将内容添加到已接受的url方案中。

        2
  •  1
  •   fisch2    12 年前

    我也遇到了同样的问题,特别是试图用forge.file.getImage返回的文件的src显示img。Angular将unsafe:添加到本地img URL的content:前缀中,正如connorhd所说,您需要将content:添加到URL白名单中。

    请注意,compileProvider的API随着Angular的最新版本发生了变化,所以我在这里发表评论,以防其他人发现此解决方案的更新版本很有用。

    app.config(['$compileProvider', 
    function($compileProvider) {
        $compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel|content|blob):|data:image|/);
        // note: you'll also have to do imgSrcSanitizationWhitelist if you want to use general links as well as ng-src on images.
    }]);
    
        3
  •  0
  •   iilakkiah ilangovan    10 年前

    我也遇到了这个问题——只需在config.xml中添加消毒液

    var app = angular.module( 'myApp', [] )
    .config( [
        '$compileProvider',
        function( $compileProvider )
        {   
            $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
            // Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...)
        }
    ]);