gpt4 book ai didi

javascript - 检测国家和重定向

转载 作者:太空宇宙 更新时间:2023-11-04 14:37:57 25 4
gpt4 key购买 nike

这是我的代码,但它不起作用。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="http://api.wipmania.com/jsonp?callback.js"></script>
<script type="text/javascript">
switch(country_code()){
case "IN" :
document.location.href = "http://xxxxxxxx.biz/theme.php";
break;
}
</script>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
</html>

我想检测用户的国家并适本地重定向他们。

最佳答案

您使用的 wipmania 链接有误,它需要包含可以执行的函数的名称。您可以通过两种方式使用它,一种是通过使用 jquery 的 jsonp ajax 调用:

$.ajax({
url:"http://api.wipmania.com/jsonp?callback=?",
dataType:"jsonp"
}).done(function(data){
switch(data.address.country_code){
case "IN" :
document.location.href = "http://xxxxxxxx.biz/theme.php";
break;
}
});

或者在您的代码中创建一个函数,然后在 wipmania 链接中使用该函数的名称

<script>
function determineCountry(data){
switch(data.address.country_code){
case "IN" :
document.location.href = "http://xxxxxxxx.biz/theme.php";
break;
}
}
</script>
<script type="text/javascript" src="http://api.wipmania.com/jsonp?callback=determineCountry"></script>

关于javascript - 检测国家和重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21746284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com