使用 window.open in JavaScript 的 URL 中的“/”问题

issues with "/" in a url using window.open in javascript

本文关键字:中的 问题 URL window open in JavaScript 使用      更新时间:2023-09-26

我想分享的网址很简单 http://www.mysite.com/123.php此代码不起作用。 我尝试过编码URIComponent和encodeURI,但没有运气。

<script>
function fbs_click(id) {
u='http://www.mysite.com/';
t = id + '.php';
window.open('http://www.facebook.com/sharer.php?s=100&p[title]=Check it out&p[url]='+u+t,'sharer','toolbar=0,status=0,width=626,height=436');
}
</script>

Facebook打开的窗口显示"检查出来",然后 www.mysite.com。它不显示任何"/"或.com之后的内容

如果我在.com后去掉"/"并有

u='http://www.mysite.com';
t = id + '.php';

打开的窗口显示"Check it out"和www.mysite.com123.php因此问题必须与正斜杠有关。 我该如何解决这个问题?

<script>
function fbs_click(id) {
u='http://www.mysite.com/';
t = id + '.php';
window.open('http://www.facebook.com/sharer.php?s=100&p[title]=Check it out&p[url]='+u+'''+t,'sharer','toolbar=0,status=0,width=626,height=436');
}
</script>

您是否尝试单独附加"''"???

尝试下面的代码,它工作正常

window.open('http://www.facebook.com/sharer.php?s=100&p[title]=Check it out&p[url]='+u+'/'+t,'sharer','toolbar=0,status=0,width=626,height=436');