一个html页面,在url中传递中文参数给另一个html页面,我发现不同的浏览器传递的结果不一样,比如传递“网络游戏”这4个汉字,
不同的浏览器得到如下3个结果:
xxx.html?id=%CD%F8%C2%E7%D3%CE%CF%B7
xxx.html?id=%E7%BD%91%E7%BB%9C%E6%B8%B8%E6%88%8F
xxx.html?id=网络游戏有没有办法window.open(newurl)前,在js代码中规定newurl按照上面第二种方式传递中文啊?javascript中文编码

解决方案 »

  1.   

    你查下encodeURIComponent 和 decodeURIComponent方法  或许能帮助你
      

  2.   

    只要能够正常接收就没有问题,1# 的方法用上就可以了 encodeURIComponent 。
      

  3.   

    function rawurlencode(str) {
                        str = (str + '').toString();
                        return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                        replace(/\)/g, '%29').replace(/\*/g, '%2A');
                    }