Saturday, September 09, 2017

$window.open('url') directs to currenthost + url instead of just url in AngularJS

Issues:When I am trying following code in AngularJS, it works but opening new window with url like below 

http://localhost/pages/www.facebook.com

JS File
  $scope.OpenWindow = function (url, _blank) {
         window.open(url, '_blank', 'heigth=600,width=600');
     }
HTML File

 img class="FacebookIcon" ng-click="OpenWindow('www.facebook.com')"

Solution: Add 'http://' in the url

JS File
  $scope.OpenWindow = function (url, _blank) {
         window.open( "http://" + url, '_blank', 'heigth=600,width=600');
     }

It will work and open  https://www.facebook.com

No comments: