У меня есть страница с кнопкой «Поделиться в 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
, а также в URL-адрес share.php Facebook в качестве строки запроса (например, 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/