URL重定向问题

时间:2015-08-21 10:06:53

标签: javascript angularjs url redirect

网址重定向无效,即

我使用filter来替换与我的锚标签匹配的字符串。

DEMO

控制器

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

app.filter('parseUrlFilter', function ($sce) {
    var urlPattern = /(^|\s)((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi;
    return function (text, target, otherProp) {
           text = text.replace(urlPattern, '<a target="' + target + '" href="$&">$&</a>');
           return $sce.trustAsHtml(text);
    };
});

function Ctrl($scope) {
    $scope.text = 'Example text http://example.com http://example.com http://google.com google.com';
}

HTML

<div ng-controller="Ctrl">
     <p ng-bind-html="text | parseUrlFilter:'_blank'"></p>
</div>

我的问题是,当网址有http或https时,它会将我们正确地重定向到相应的网页,即如果&#34; http://google.com&#34; 它正常运行。但如果 http或https丢失,然后它无法正常工作,即如果 google.com 它没有重定向到google.com而是重定向到localhost / folder / google .COM。

0 个答案:

没有答案
相关问题