我有一個帶有Facebook分享按鈕的頁面。我想分享的URL上有一個查詢字符串,我用javascript構建。下面是我如何生成共享URL ..Facebook忽略共享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抓住網址因爲某些原因離開其關閉這是在queryString
可變創造了一切。因此,共享網址最終只是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/