<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>
这样可以做到判断,但是客户提出新要求,就是第一次做判断,以后再进就不判断了,可以随意进入中文或者英文。抓狂啊

解决方案 »

  1.   

    你可以给个全局变量或一个session保存数字,第一次判断后给变量赋值1,当变量为1时不再判断。
      

  2.   


    <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.哎!
      

  3.   

    我的意思str=-1的时候做判断,str=1就不做了。不知道为什么不行?哈哈,菜
      

  4.   

    你还是犯刚才一样的错误,str一直为为-1,
    刷新页面后所有js变量重新初始化str为-1
      

  5.   

    用js操作cookie,cookie保存下来那个id,页面加载时判断 是否为空
    否则,取出直接跳转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";
            }
        }
    }
      

  6.   

    lz了解下cookie吧,cookie可以很轻松解决,7楼正解的
      

  7.   


    <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>
    大家看看那个地方错误了?
      

  8.   


    <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>这个在我自己的电脑上测试好像是可以啦,但是在某些电脑上不能成功。
      

  9.   


    看看不行的电脑是否禁用了JS或是COOKIE
      

  10.   

    很崩溃!现在id=191是中文本版,id=471是英文版本.假如客户是中文IE浏览器。直接进入id=191的话,没问题,这个时候,他们需要再点英文链接id=471直接进入?不需要再判断是否中英文了。我不知道这样能不能实现。假如要实现这个,就没有做判断的需要了,直接点中英文来回切换就好了.如果英文版本的一次都不判断。我cookie怎么写?