find_str: 查找的字符串
r_str: 代替的字符
function replace(find_str, r_str, t_str) {
var b = find_str.split(r_str);
find_str = "";
for (var c in b) {
if (c != 0) {
find_str = t_str+b[c]+find_str;
} else {
find_str = b[c]+find_str;
}
}
return find_str;
}
var b = find_str.split(r_str);
find_str = "";
for (var c in b) {
if (c != 0) {
find_str = t_str+b[c]+find_str;
} else {
find_str = b[c]+find_str;
}
}
return find_str;
}
比如,Flash打开的网址里面 # 和 , 之类的符号不能传递到浏览器,可以用escape进行转换:将参数转换为字符串,并以 URL 编码格式进行编码,在这种格式中,将所有非字母数字的字符都转义为 % 十六进制序列。
url="http://mccannmsnbjafa.allyes.com/main/adfclick?db=mccannmsnbjafa&bid=215,212,6&cid=198,5,1&sid=429&advid=1&camid=6&show=ignore&url=http://www.msn.com.cn";
url=replace(url,"#",escape("#"));
url=replace(url,",",escape(","));
//当然,把需要转换的字符都转换就好了
getURL(url,"_blank");
出错例子:
http://localhost/test.php?i=d11,2,33 getURL之后得到:http://localhost/test.php?i=d1
http://localhost/test.php?i=d,2,33 getURL之后得到:http://localhost/test.php?i=
原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
关注一下Web 2.0
《雾都孤儿》观感
