【发布时间】:2023-04-02 15:14:01
【问题描述】:
我想知道您是否可以给我一个有效的代码,这样当有人从英国加载网站时,它会将用户重定向到 /UK/,然后如果他们从美国加载它,它会转到 /US/,如果他们'来自除英国以外的欧盟任何地方到 /EU/
我试过这段代码,它只是说 123。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>removed</title>
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition,showError);
}
else
{
alert("Geolocation is not supported by this browser.");
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
alert("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.");
break;
case error.TIMEOUT:
alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("An unknown error occurred.");
break;
}
}
function showPosition(pos)
{
if (pos.coords.longitude >= 45.775534 && pos.coords.longitude <= 45.775562 && pos.coords.latitude <= 15.994809 && pos.coords.latitude >= 15.994792)
{
alert("987");
//window.location = 'USD/';
}
else{
alert("123");
// window.location = 'GBP/';
}
}
}//]]>
</script>
</head>
<body>
</body>
</html>
【问题讨论】:
标签: javascript jquery html css geoip