不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
Firefox自动对url中的中文进行编码导致乱码
编辑:dnawo 日期:2008-01-16
先看下面一个例子:
index.htm:
002.htm:
003.htm:
分别在IE和Firefox打开http://localhost/index.htm可以得到以下结果:
IE:002.htm和003.htm都显示正常;
Firefox:002.htm显示为乱码,003.htm显示正常;
Firefox乱码的原因是由于Firefox对地址中的中文采取了不同于IE的编码方式(网上说法),也就是说:
当url参数值含有中文时必须使用escape进行编码!
测试中还发现,当参数值没有用escape进行编码时,使用unescape进行解码IE下不会乱码,但Firefox下会乱码!
index.htm:
复制内容到剪贴板
程序代码

<script language="javascript">
title = "木子屋";
document.write("参数值未编码(http://localhost/003.htm?title=木子屋):<br/>");
document.writeln("<iframe width=\"300\" height=\"300\" src=\"http://localhost/002.htm?title="+title+"\" frameborder=1 marginwidth=0 marginheight=0></iframe>");
document.writeln("</p>");
document.write("参数值编码(http://localhost/003.htm?title=%u6728%u5B50%u5C4B):<br/>");
document.writeln("<iframe width=\"300\" height=\"300\" src=\"http://localhost/003.htm?title="+escape(title)+"\" frameborder=1 marginwidth=0 marginheight=0></iframe>");
</script>
title = "木子屋";
document.write("参数值未编码(http://localhost/003.htm?title=木子屋):<br/>");
document.writeln("<iframe width=\"300\" height=\"300\" src=\"http://localhost/002.htm?title="+title+"\" frameborder=1 marginwidth=0 marginheight=0></iframe>");
document.writeln("</p>");
document.write("参数值编码(http://localhost/003.htm?title=%u6728%u5B50%u5C4B):<br/>");
document.writeln("<iframe width=\"300\" height=\"300\" src=\"http://localhost/003.htm?title="+escape(title)+"\" frameborder=1 marginwidth=0 marginheight=0></iframe>");
</script>
002.htm:
复制内容到剪贴板
程序代码

<script language="javascript">
//获取查询字符串中的参数值
function GetParam(parmName)
{
var url = document.location.search;
if(url!="undefined")
{
var arrParam = url.split("&");
for(var i =0;i<arrParam.length;i++)
{
var loc = arrParam[i].indexOf(parmName+"=");
if(loc!=-1)
{
return arrParam[i].replace(parmName+"=","").replace("?","");
break;
}
}
}
}
document.write("title:" + GetParam("title"));
</script>
//获取查询字符串中的参数值
function GetParam(parmName)
{
var url = document.location.search;
if(url!="undefined")
{
var arrParam = url.split("&");
for(var i =0;i<arrParam.length;i++)
{
var loc = arrParam[i].indexOf(parmName+"=");
if(loc!=-1)
{
return arrParam[i].replace(parmName+"=","").replace("?","");
break;
}
}
}
}
document.write("title:" + GetParam("title"));
</script>
003.htm:
复制内容到剪贴板
程序代码

<script language="javascript">
//获取查询字符串中的参数值
function GetParam(parmName)
{
var url = document.location.search;
if(url!="undefined")
{
var arrParam = url.split("&");
for(var i =0;i<arrParam.length;i++)
{
var loc = arrParam[i].indexOf(parmName+"=");
if(loc!=-1)
{
return arrParam[i].replace(parmName+"=","").replace("?","");
break;
}
}
}
}
document.write("title(解码):" + unescape(GetParam("title")));
</script>
//获取查询字符串中的参数值
function GetParam(parmName)
{
var url = document.location.search;
if(url!="undefined")
{
var arrParam = url.split("&");
for(var i =0;i<arrParam.length;i++)
{
var loc = arrParam[i].indexOf(parmName+"=");
if(loc!=-1)
{
return arrParam[i].replace(parmName+"=","").replace("?","");
break;
}
}
}
}
document.write("title(解码):" + unescape(GetParam("title")));
</script>
分别在IE和Firefox打开http://localhost/index.htm可以得到以下结果:
IE:002.htm和003.htm都显示正常;
Firefox:002.htm显示为乱码,003.htm显示正常;
Firefox乱码的原因是由于Firefox对地址中的中文采取了不同于IE的编码方式(网上说法),也就是说:
当url参数值含有中文时必须使用escape进行编码!
测试中还发现,当参数值没有用escape进行编码时,使用unescape进行解码IE下不会乱码,但Firefox下会乱码!
评论: 0 | 引用: 0 | 查看次数: 9453
发表评论
请登录后再发表评论!