【发布时间】:2011-06-17 22:38:10
【问题描述】:
我对 javascript 了解得不够多,无法弄清楚为什么此脚本中以“window.open...”开头的行会在 IE7-8-9b 中引发无效参数错误。在 Firefox 和 Webkit 中运行良好。
(该脚本在 html 链接中使用 onclick="share.fb()" 进行调用,并弹出一个新的浏览器窗口以在 FB 和 Twitter 上共享)。
var share = {
fb:function(title,url) {
this.share('http://www.facebook.com/sharer.php?u=##URL##&t=##TITLE##',title,url);
},
tw:function(title,url) {
this.share('http://twitter.com/home?status=##URL##+##TITLE##',title,url);
},
share:function(tpl,title,url) {
if(!url) url = encodeURIComponent(window.location);
if(!title) title = encodeURIComponent(document.title);
tpl = tpl.replace("##URL##",url);
tpl = tpl.replace("##TITLE##",title);
window.open(tpl,"sharewindow"+tpl.substr(6,15),"width=640,height=480");
}
};
【问题讨论】:
-
您是否尝试在
fb和tw函数中将this.share切换为share.share?
标签: javascript internet-explorer javascript-events