解决新浪微博分享按钮 中文URL出错的问题
日期:2011-11-03 阅读:58 分类:Web前端
本站使用了新浪微博的分享按钮,但遇到了一个问题;由于本站的编码统一是GBK,并且有的页面URL里面包含有中文,那么由于新浪微博的分享代码用的是encodeURIComponent,是按UTF-8的方式编码的,那么这些中文URL传递过去之后就会遇到问题。
看代码:
function loadSinaShare() {扩展阅读:Javascript URL编码方法的比较
var logoPanel = document.getElementById("logoPanel");
if(!logoPanel)
{
return;
}
var _w = 90 , _h = 24;
var param = {
url:location.href,
type:'2',
count:'1',
appkey:'',
title:'',
pic:'',
ralateUid:'1508522870',
rnd:new Date().valueOf()
};
var temp = [];
for( var p in param ){
temp.push(p + '=' + escape( param[p] || '' ) );
//此处原来不是escape,原来为encodeURIComponent
}
var iframe = document.createElement("iframe");
iframe.allowTransparency = true;
iframe.frameBorder = 0;
iframe.scrolling = "no";
iframe.width = _w;
iframe.height = _h;
iframe.style.marginLeft = "4px";
iframe.src = "http://hits.sinajs.cn/A1/weiboshare.html?"+ temp.join('&');
logoPanel.appendChild(iframe);
}
相关文章
- 不必“取消关注”也可以让某人微博从你的首页消失 2011-11-16
- url与uri的区别 2008-12-11
- Javascript URL编码方法的比较 2008-09-02
- 请求筛选模块被配置为拒绝包含hiddenSegment节的URL中的路径 2011-07-28
- 在Windows下使用curl命令 2009-03-23
- URL格式规范 2008-12-17
- 按钮在 IE 中两边被拉伸的 BUG 2011-11-26
- Google为图片搜索添加+1按钮 2011-11-10
- 网页重构之资源加载和优化 2011-09-09
- 新浪微博是新浪唯一的救命稻草 2011-10-18
- 也谈Twitter和新浪微博 2011-10-18