我对此很陌生,一直在尝试,我想知道是否可以自动将人们从登陆页面重定向到包含其状态信息的页面。
喜欢 url.com/至 url.com/michigan.htm
我找到的当前代码
<script language="Javascript" src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesLocationCode,GeobytesCode,GeobytesInternet"></script>
<script language="Javascript">
if(typeof(sGeobytesLocationCode)=="undefined"
||typeof(sGeobytesCode)=="undefined"
||typeof(sGeobytesInternet)=="undefined")
{
// Something has gone wrong with the variables, so set them to some default value,
// maybe set a error flag to check for later on.
var sGeobytesLocationCode="unknown";
var sGeobytesCode="unknown";
var sGeobytesInternet="unknown";
}
if(sGeobytesCode=="MI")
{
// Visitors from Michigan would go here
window.open("http://www.url.com/michigan.htm" , "_self");
}else if(sGeobytesInternet=="US")
{
// Visitors from The United States would go here
window.open("http://www.url.com/selectstate.htm");
}
</script>
我注意到我需要做什么来向这段代码添加更多状态,我确信它很简单,但就像我说的,我对此很陌生
谢谢
最佳答案
我建议使用 switch
语句,以便轻松添加所需数量的状态。另外,window.open
打开一个新窗口,这可能会很烦人,因此最好使用 window.location
在同一窗口中重定向用户。
替换这个:
if(sGeobytesCode=="MI")
{
// Visitors from Michigan would go here
window.open("http://www.url.com/michigan.htm" , "_self");
}else if(sGeobytesInternet=="US")
{
// Visitors from The United States would go here
window.open("http://www.url.com/selectstate.htm");
}
像这样:
switch (sGeobytesCode) {
case 'MI': window.location = 'http://www.url.com/michigan.htm'; break;
case 'AA': window.location = 'something'; break;
case 'BB': window.location = 'something else'; break;
...
default:
if(sGeobytesInternet=="US")
{
// Visitors from The United States would go here
window.location = 'http://www.url.com/selectstate.htm';
}
break;
}
关于javascript - 有没有一种方法可以根据人们的状态自动将他们重定向到不同的页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3792460/