简单的方法就是这个。 将http://smart-ip.net/geoip结合为JSON和jQuery:
$(document).ready( function() {
$.getJSON( "http://smart-ip.net/geoip-json?callback=?",
function(data){
alert( data.host);
}
);
});
翻译自: https://bytes.com/topic/javascript/insights/933428-easy-way-get-ip-javascript