我希望通过IP选择进行链接重定向。但没有工作,任何想法?
获取IP
<script>
$.get("http://ipinfo.io", function (response) {
$("#address").html(response.region);
}, "jsonp");
</script>
<div style="display:none;" id="address" name="address"></div>
重定向脚本
<script type="text/javascript">
function Redirect() {
var address = document.getElementById("address").value;
window.location.replace = "https://google.com/"+address+"";
}
document.write("You will be redirected to main page in 0 sec.");
setTimeout('Redirect()', 0);
</script>
答案 0 :(得分:3)
获取IP&amp;重定向链接
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript">
$.getJSON('http://ipinfo.io', function (response) {
$("#address").html(response.region);
var address = (response.region);
window.location = "https://google.com/"+address+"";
});
</script>