最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Detect Country And Redirect - Stack Overflow

programmeradmin1浏览0评论

Here is my code, but it's not working.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
".dtd">
<html xmlns="" xml:lang="en" lang="en">
<head>
<script src=".3.2/jquery.min.js"></script>
<script src=".js"></script>
<script type="text/javascript">
switch(country_code()){
case "IN" :
        document.location.href = ".php";
        break;
}
</script> 
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
</html>

I want to detect the user's country and redirect them appropriately.

Here is my code, but it's not working.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="http://api.wipmania./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>

I want to detect the user's country and redirect them appropriately.

Share Improve this question edited Feb 13, 2014 at 5:55 Josh Lowe 4843 silver badges13 bronze badges asked Feb 13, 2014 at 5:52 user3304678user3304678 251 silver badge4 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 6

You are using the wipmania link wrong it needs to have the name of a function in it that can be executed. You can use it in two ways one through an jsonp ajax call with jquery:

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

or create a function in your code and then use the name of that function in the wipmania link

<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./jsonp?callback=determineCountry"></script>

You could achieve this with php. This should get you there.

<?php
// ccr.php - country code redirect
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
$country_code = $geoplugin->countryCode;
switch($country_code) {
case 'US':
header('Location: http://www.domain./links/usa.php');
exit;
case 'CA':
header('Location: http://www.domain./links/canada.php');
exit;
case 'GB':
header('Location: http://www.domain./links/greatbritain.php');
exit;
case 'IE':
header('Location: http://www.domain./links/ireland.php');
exit;
case 'AU':
header('Location: http://www.domain./links/australia.php');
exit;
case 'NZ':
header('Location: http://www.domain./links/newzealand.php');
exit;
default: // exceptions
header('Location: http://www.domain./links/allelse.php');
exit;
}
?>

More info and supporting plugin download:

http://www.trafficplusconversion./251/redirect-based-on-country/

Here is a JavaScript option.

http://www.geobytes./GeoDirection.htm

发布评论

评论列表(0)

  1. 暂无评论