Javascript 如何使用位置服务打开url
我在使用Javascript 如何使用位置服务打开url,javascript,angularjs,ionic,Javascript,Angularjs,Ionic,我在使用时遇到困难,您可以使用$window.open(url,'.\u blank') 或 你们可以看看,我在其中做了这样的更改,你们可以重定向到另一个页面,从ui路由器状态本身 您还可以通过添加外部参数来定制ui路由器,它可以是真/假 $stateProvider .state('external', { url: 'http://www.google.com', external: true }) 然后在您的状态中配置$stateChangeStart并在那里处理重定
时遇到困难,您可以使用$window.open(url,'.\u blank')
或
你们可以看看,我在其中做了这样的更改,你们可以重定向到另一个页面,从ui路由器
状态本身
您还可以通过添加外部参数来定制ui路由器,它可以是真/假
$stateProvider
.state('external', {
url: 'http://www.google.com',
external: true
})
然后在您的状态中配置$stateChangeStart并在那里处理重定向部分
运行块
myapp.run(function($rootScope, $window) {
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams) {
if (toState.external) {
event.preventDefault();
$window.open(toState.url, '_self');
}
});
})
最好使用$stateProvider,您还需要将白名单插件添加到
获取外部资源
像这样使用$stateProvider
.config(function($stateProvider, $urlRouterProvider) {
// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state's controller can be found in controllers.js
$stateProvider
// setup an abstract state for the tabs directive
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html'
})
// Each tab has its own nav history stack:
.state('tab.dash', {
url: '/dash',
views: {
'tab-dash': {
templateUrl: 'templates/tab-dash.html',
controller: 'indexController'
}
}
})
.state('tab.chats', {
url: '/chats',
views: {
'tab-chats': {
templateUrl: 'templates/tab-chats.html',
controller: 'CenterListController'
}
}
})
.state('tab.chat-detail', {
url: '/chats/:centerId',
views: {
'tab-chats': {
templateUrl: 'templates/chat-detail.html',
cache:true,
controller: 'CenterDetailController'
}
}
})
.state('tab.manual-Location', {
url: '/manualLocation',
views: {
'tab-account': {
templateUrl: 'templates/tab-account.html',
controller: 'ManualLocationController'
}
}
})
.state('tab.manual-Location-List', {
url: '/manualLocationList/:locationID',
views: {
'tab-account': {
templateUrl: 'templates/manualLocationList.html',
controller: 'ManualLocationListController'
}
}
})
.state('tab.manual-Location-Detail', {
url: '/manualLocationDetail/:centerId',
views: {
'tab-account': {
templateUrl: 'templates/manual-Location-Detail.html',
controller: 'ManualLocationDetailController'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/tab/dash');
});
你可以用
$window.location.href = 'http://google.com'
完整的代码应该是
app.controller("listController", ['$scope', '$location', '$window', function($scope, $location, $window) {
$scope.go_to = function() {
alert("a"); //CALLED
var url = "http://google.com";
$window.location.href = url;
};
}]);
对我来说,一个简单的方法是:
<a href="...">
<li class="item" ng-click="go_to()">
<img src="img/ionic.png">
<p>Beginners Guide</p>
</li>
</a>
$location服务的设计目的不是导航并重新加载当前页面。它是为单页应用程序设计的
$location服务只允许您更改URL;事实并非如此
允许您重新加载页面。当您需要更改URL和
重新加载页面或导航到其他页面,请使用较低的
级别API,$window.location.href
如果您试图导航到其他页面,请使用:
$window.location.href = "http://www.google.com";
如果您使用的是ui路由器。您可以使用您可以使用以下代码解决此问题
$window.open("http://google.com", "_blank");
这将在下一个选项卡中打开url
这是解决您问题的有效方法之一
$scope.go_to = function() {
alert("a"); //CALLED
var url = "http://google.com";
$window.open(url, "_blank");
};
终于找到了罪犯:)
这是因为我在我的索引中对这段代码进行了注释
:
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
在那之后,我只需要使用一个基本的href
试试window.location.href='www.google.com'
锚有什么问题?@Tushar他想给点击整个li
事件,我想他可以做我建议的改变。初学者指南
应该有效,不需要a
中的li
,只保留大量图像。当我将标签放入中时,标签不起作用(item
是离子类)。我还尝试将
放在
中,如果我使用项
类,它仍然不起作用
$scope.go_to = function() {
alert("a"); //CALLED
var url = "http://google.com";
$window.open(url, "_blank");
};
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>