如何在新标签

时间:2017-03-06 09:24:29

标签: javascript jquery angularjs angular-ui-router url-routing

我试图在newtab中打开一个状态但是无法实现它。我这样做是使用$ state,go function。

我也尝试了以下代码,这是成功的,并在newtab中打开我的网址,但浏览器阻止在新标签中打开新网址。

   openurlnw = $state.href('home.forward',{"url":$scope.platforms[0].url,"name":$scope.platforms[0].name,"dish_name":$scope.userSearchedDish});
   window.open(openurlnw,'_blank');

我想在新标签页中打开状态,而不让浏览器阻止它。

1 个答案:

答案 0 :(得分:2)

您必须在构建网址时使用absolute选项,然后使用$window.open

替换:

openurlnw = $state.href('home.forward',{"url":$scope.platforms[0].url,"name":$scope.platforms[0].name,"dish_name":$scope.userSearchedDish});

使用:

openurlnw = $state.href('home.forward',{"url":$scope.platforms[0].url,"name":$scope.platforms[0].name,"dish_name":$scope.userSearchedDish}, {absolute:true});

然后:

$window.open(openurlnw,'_blank');