在我的页面中有一个按钮,我想放置一些链接取决于用户所在的国家/地区。
例如,我把这段代码放在角度来理解我的观点。
这段代码对我不起作用。
我错过了什么吗?
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="http://getbootstrap.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<link href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css" rel="stylesheet">
<script src="http://getbootstrap.com/assets/js/ie-emulation-modes-warning.js"></script>
<script>
var app = angular.module('gJson', []);
app.controller('gCtrl', function($scope, $http) {
$http.get("//freegeoip.net/json/?callback=myGeoIP")
.success(function myGeoIP(d) {
if (d.country_code === 'US' || d.country_code === 'CA') {
$scope.alertz = "This Offer Available in + d.country_code";
$scope.uslink = 'http://example.US';
}
else
{
$scope.alertz = "This Offer Not Available in + d.country_code";
$scope.uslink = "http://Example.net";
}
});
});
</script>
</head>
<body ng-app="gJson">
<div class="container" ng-controller="gCtrl">
<div class="jumbotron">
<p>{{alertz}}</p>
<a class="btn btn-lg btn-success" ng-href="{{uslink}}" onclick="window.open(this.href, '_self', 'location=yes', 'toolbar=yes');">
Enter
</a>
</div>
</div>
</body>
</html>