【发布时间】:2014-11-18 06:24:53
【问题描述】:
我想在 Github 上托管一个不支持 php 的网页,然后将除中国以外的所有访问者重定向到另一个网站(托管在 Weebly 上)。
原因是 Weebly 在中国被屏蔽,但提供了更好的用户体验。
在没有启用 PhP 的情况下如何做到这一点?有没有办法在 Javascript 中做到这一点?
【问题讨论】:
标签: javascript html url url-redirection
我想在 Github 上托管一个不支持 php 的网页,然后将除中国以外的所有访问者重定向到另一个网站(托管在 Weebly 上)。
原因是 Weebly 在中国被屏蔽,但提供了更好的用户体验。
在没有启用 PhP 的情况下如何做到这一点?有没有办法在 Javascript 中做到这一点?
【问题讨论】:
标签: javascript html url url-redirection
您可以使用geoPlugin
先添加
<script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>
到你的网页
那就试试这个
document.write("Welcome to our visitors from "+geoplugin_countryName());
<script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>
</head>
【讨论】:
你也可以使用 ipinfo.io
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET', '//ipinfo.io', true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
var obj = JSON.parse(xmlhttp.responseText);
if (obj.country != 'CN')
window.location.replace('http://www.weebly.com/...');
}
}
};
xmlhttp.send(null);
【讨论】:
document.write("Welcome to our visitors from "+geoplugin_countryName());
<script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>
</head>
【讨论】:
<script>
function geo(a) {
switch (a.country.code)
{
case "SE": // Redirect is visitor from Sweden
case "NO": // Redirect is visitor from Norway
case "FR": // Redirect is visitor from FRANCE
case "PL": // Redirect is visitor from POLAND
case "GY": // Redirect is visitor from GERMANY
window.location = "https://se.brixtol.com" + window.location.pathname; // edit for your URL
break;
default:
return null;
}
}
</script>enter code here`
<script src="https://geoip.nekudo.com/api?callback=geo"></script>
</pre>
【讨论】: