<script>
var wn=window.navigator;
var href=location.href;
if ((wn.systemLanguage=="zh-cn" || wn.language=="zh-CN") && href.indexOf("id=191")==-1) {
window.location = "http://www.zhongda.com/index.php?id=191";
}
else if ((wn.systemLanguage=="en" || wn.language=="zh-EN") && href.indexOf("id=471")==-1) {
window.location = "http://www.zhongda.com/index.php?id=471";
}
</script>
这样可以做到判断,但是客户提出新要求,就是第一次做判断,以后再进就不判断了,可以随意进入中文或者英文。抓狂啊
var wn=window.navigator;
var href=location.href;
if ((wn.systemLanguage=="zh-cn" || wn.language=="zh-CN") && href.indexOf("id=191")==-1) {
window.location = "http://www.zhongda.com/index.php?id=191";
}
else if ((wn.systemLanguage=="en" || wn.language=="zh-EN") && href.indexOf("id=471")==-1) {
window.location = "http://www.zhongda.com/index.php?id=471";
}
</script>
这样可以做到判断,但是客户提出新要求,就是第一次做判断,以后再进就不判断了,可以随意进入中文或者英文。抓狂啊
<script>
var wn=window.navigator;
var href=location.href;
var str=-1;
if(str=-1){
if ((wn.systemLanguage=="zh-cn" || wn.language=="zh-CN") && href.indexOf("id=191")==-1) {
window.location = "http://www.zhongda.com/index.php?id=191";
str=1;
break;
} else if ((wn.systemLanguage=="en" || wn.language=="zh-EN") && href.indexOf("id=471")==-1) {
window.location = "http://www.zhongda.com/index.php?id=471";
str=1;
break;
}
}
else
window.location="http://www.zhongda.com/index.php?id=191";
</script>
不懂javascript.哎!
刷新页面后所有js变量重新初始化str为-1
否则,取出直接跳转var cookie={
/*cookie*/
/**
* Sets a Cookie with the given name and value.
*
* name Name of the cookie
* value Value of the cookie
* [expires] Expiration date of the cookie (default: end of current session)
* [path] Path where the cookie is valid (default: path of calling document)
* [domain] Domain where the cookie is valid
* (default: domain of calling document)
* [secure] Boolean value indicating if the cookie transmission requires a
* secure transmission
*/
setCookie:function(name,value,hours,path,domain,secure) {
var expires="";
if(hours) {
var date = new Date();
date.setTime(date.getTime()+(hours*60*60*1000));
expires = ";expires="+date.toGMTString();
}
document.cookie = name + "=" +escape(value)+
//(expires?(";expires="+expires.toGMTString()):"")+
expires+
(path?(";path="+path):"")+
(domain?(";domain="+domain):"")+
(secure?(";secure="+secure):"");
},
/**
*Get the value of the specified cookie
*
*@param {String} name The name of the desired cookie
*Returns a string containing value of specified cookie,
* or null if cookie does not exist.
*/
getCookie:function(name) {
var dc = document.cookie;
var prefix = name+"=";
var begin = dc.indexOf("; " + prefix);
if(begin==-1) {
begin = dc.indexOf(prefix);
if(begin!=0)return null;
}else {
begin+=2;
}
var end=document.cookie.indexOf(";",begin);
if(end==-1){
end=dc.length;
}
return unescape(dc.substring(begin + prefix.length,end));
},
/**
* Deletes the specified cookie.
*
* name name of the cookie
* [path] path of the cookie (must be same as path used to create cookie)
* [domain] domain of the cookie (must be same as domain used to create cookie)
*/
delCookie:function(name,path,domain) {
if(this.getCookie(name)) {
document.cookie = name + "=" +
(path?(";path="+path):"") +
(domain?(";domain="+domain):"") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
}
<script>var cookie={
/*cookie*/
/**
* Sets a Cookie with the given name and value.
*
* name Name of the cookie
* value Value of the cookie
* [expires] Expiration date of the cookie (default: end of current session)
* [path] Path where the cookie is valid (default: path of calling document)
* [domain] Domain where the cookie is valid
* (default: domain of calling document)
* [secure] Boolean value indicating if the cookie transmission requires a
* secure transmission
*/
setCookie:function(name,value,hours,path,domain,secure) {
var expires="";
if(hours) {
var date = new Date();
date.setTime(date.getTime()+(hours*60*60*1000));
expires = ";expires="+date.toGMTString();
}
document.cookie = name + "=" +escape(value)+
//(expires?(";expires="+expires.toGMTString()):"")+
expires+
(path?(";path="+path):"")+
(domain?(";domain="+domain):"")+
(secure?(";secure="+secure):"");
},
/**
*Get the value of the specified cookie
*
*@param {String} name The name of the desired cookie
*Returns a string containing value of specified cookie,
* or null if cookie does not exist.
*/
getCookie:function(name) {
var dc = document.cookie;
var prefix = name+"=";
var begin = dc.indexOf("; " + prefix);
if(begin==-1) {
begin = dc.indexOf(prefix);
if(begin!=0)return null;
}else {
begin+=2;
}
var end=document.cookie.indexOf(";",begin);
if(end==-1){
end=dc.length;
}
return unescape(dc.substring(begin + prefix.length,end));
},
/**
* Deletes the specified cookie.
*
* name name of the cookie
* [path] path of the cookie (must be same as path used to create cookie)
* [domain] domain of the cookie (must be same as domain used to create cookie)
*/
delCookie:function(name,path,domain) {
if(this.getCookie(name)) {
document.cookie = name + "=" +
(path?(";path="+path):"") +
(domain?(";domain="+domain):"") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
}
var wn=window.navigator;
var href=location.href;
if(cookie.getCookie("ComeInFirst")==null){if ((wn.systemLanguage=="zh-cn" || wn.language=="zh-CN") && href.indexOf("id=191")==-1) {
window.location = "http://www.zhongda.com/index.php?id=191";
cookie.setCookie("ComeInFirst","true","24","/","www.zhongda.com/index.php?id=191","")
}
else if ((wn.systemLanguage=="en" || wn.language=="zh-EN") && href.indexOf("id=471")==-1) {
window.location = "http://www.zhongda.com/index.php?id=471";
cookie.setCookie("ComeInFirst","true","24","/","www.zhongda.com/index.php?=471","")
}
} </script>
大家看看那个地方错误了?
<script language="JavaScript" type="text/JavaScript"> //写cookies函数 作者:翟振凯var cookie={
function SetCookie(name,value)//两个参数,一个是cookie的名子,一个是值
{
var Days = 30; //此 cookie 将被保存 30 天
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;}
function delCookie(name)//删除cookie
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
}
if(cookie.getCookie("str")==null){
var wn=window.navigator;
var href=location.href;
if ((wn.systemLanguage=="zh-cn" || wn.language=="zh-CN") && href.indexOf("id=191")==-1) {
window.location = "http://www.zhongda.com/index.php?id=191";
cookie.SetCookie ("str", "http://www.zhongda.com")
} else if ((wn.systemLanguage=="en" || wn.language=="zh-EN") && href.indexOf("id=471")==-1) {
window.location = "http://www.zhongda.com/index.php?id=471";
cookie.SetCookie ("str", "http://www.zhongda.com")
}
}</script>这个在我自己的电脑上测试好像是可以啦,但是在某些电脑上不能成功。
看看不行的电脑是否禁用了JS或是COOKIE