如何将 geoip_country_code() Geoip1 javascript 脚本转换为 Geoip2
How to Convert geoip_country_code() Geoip1 javascript script to Geoip2
所以我有这段代码,我想将其转换为 Geoip2:
window.onload = function(){
var eu = ['AT','DE','BE','ES','FI','FR','IE','IT','LU','NL','PT','GR','SI','CY','MT','SK','EE'];
var country = geoip_country_code();
var index = eu.indexOf(country);
if(index > -1){
document.getElementById('prices').src = "http://test.com";
}else{
document.getElementById('prices').src = "http://test.com";
}}
问题出在 lign 4 : geoip_country_code();不工作,我的意思是它不会 return 任何东西,也不会抛出错误。我知道这是因为geoip2中没有这个功能,所以我正在寻找替代品。
有什么想法吗?
假设你的意思是 maxmind-API:
函数的新名称是 geoip2.country
.
返回的结果将包含 country
-属性,所需的值(ISO 代码)可通过 country
- 的 iso_code
- 成员获得属性:
window.onload = function(){
geoip2.country(
function(result){
var eu = ['AT','DE','BE','ES','FI','FR','IE','IT','LU','NL','PT','GR','SI','CY','MT','SK','EE'];
var country = result.country.iso_code;
var index = eu.indexOf(country);
if(index > -1){
document.getElementById('prices').src = "http://test.com?eu=1";
}
else{
document.getElementById('prices').src = "http://test.com?eu=0";
}
},
function(error){
console.log(error);
});
}
所以我有这段代码,我想将其转换为 Geoip2:
window.onload = function(){
var eu = ['AT','DE','BE','ES','FI','FR','IE','IT','LU','NL','PT','GR','SI','CY','MT','SK','EE'];
var country = geoip_country_code();
var index = eu.indexOf(country);
if(index > -1){
document.getElementById('prices').src = "http://test.com";
}else{
document.getElementById('prices').src = "http://test.com";
}}
问题出在 lign 4 : geoip_country_code();不工作,我的意思是它不会 return 任何东西,也不会抛出错误。我知道这是因为geoip2中没有这个功能,所以我正在寻找替代品。 有什么想法吗?
假设你的意思是 maxmind-API:
函数的新名称是 geoip2.country
.
返回的结果将包含 country
-属性,所需的值(ISO 代码)可通过 country
- 的 iso_code
- 成员获得属性:
window.onload = function(){
geoip2.country(
function(result){
var eu = ['AT','DE','BE','ES','FI','FR','IE','IT','LU','NL','PT','GR','SI','CY','MT','SK','EE'];
var country = result.country.iso_code;
var index = eu.indexOf(country);
if(index > -1){
document.getElementById('prices').src = "http://test.com?eu=1";
}
else{
document.getElementById('prices').src = "http://test.com?eu=0";
}
},
function(error){
console.log(error);
});
}