2017-03-27 2 views
1

私のページにボタンがあり、私はいくつかのリンクをユーザーの国に依存したいと思っています。リンクを変更するにはどうすればよいですか?

私はこの点を理解するために、このコードを例に挙げています。

このコードは機能しません。

私は何かを見逃しましたか? URLを変更すると

<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> 

答えて

1

変更//freegeoip.net/json/?callback

から//freegeoip.net/json/?callback=myGeoIPからurlは今では成功の結果が対象となりますmyGeoIp({"city":"","country_code":""...});

のような文字列を返すと、あなたはコードが

に動作します
関連する問題