【发布时间】:2013-10-06 16:15:06
【问题描述】:
我有一个带有 Facebook 分享按钮的页面。我要共享的 URL 上有一个我用 javascript 构建的查询字符串。这是我生成要共享的 URL 的方式..
queryString = "cup=blue&bowl=red&spoon=green";
//the values of this are actually generated by user input, don't think its important for this example though. So in this example its just a basic string.
siteURL = "http://example.com/?share=1&";
//the url without the query string
sharingURL = siteURL+queryString;
//Combing the domain/host with query string.. sharingURL should = http://example.com?share=1&cup=blue&bowl=red&spoon=green
function FBshare(){
shareURL = siteURL+queryString;
console.log(shareURL);
window.open(
'https://www.facebook.com/sharer/sharer.php?u='+shareURL,
'facebook-share-dialog',
'width=626,height=436');
return false;
}
$(".facebook").bind("click", function(){
FBshare();
});
当 facebook 出于某种原因获取 URL 时,它会忽略在 queryString 变量中创建的所有内容。所以共享的 URL 最终只是 http://example.com/?share=1。有什么想法为什么要放弃 queryString 变量?正确的 URL 被放入 console.log 就好了,加上它在 Facebook share.php URL 中作为查询字符串(例如 https://www.facebook.com/sharer/sharer.php?u=http://example.com/?share=1&cup=blue&bowl=red&spoon=green).. 但 Facebook 上的实际链接不完整。
这是一个 jsFiddle。 http://jsfiddle.net/dmcgrew/gawrv/
【问题讨论】:
标签: javascript jquery facebook facebook-sharer