2013-09-30 19 views
9

Facebook Paylaş düğmesi olan bir sayfam var. Paylaşmak istediğim URL'nin üzerinde javascript ile oluşturduğum bir sorgu dizesi var. İşte paylaşılacak URL'yi üreten ediyorum nasıl ..Facebook, paylaşım dizgimin bir kısmını yoksayılıyor 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 onun queryString değişken oluşturulan herşeyi kapalı bırakarak nedense URL'yi tutuyor zaman. Yani paylaşılan URL sadece http://example.com/?share=1 olmaktan çıkıyor. queryString değişkenini neden bıraktığına dair herhangi bir fikir var mı? Doğru URL, console.log'a girer, bununla birlikte Facebook share.php URL'sinde bir sorgu dizgisi olarak (örneğin https://www.facebook.com/sharer/sharer.php?u=http://example.com/?share=1&cup=blue&bowl=red&spoon=green) .. ama asıl bağlantı Facebook'ta eksiktir.

İşte bir jsFiddle. http://jsfiddle.net/dmcgrew/gawrv/

cevap

16

facebook URL olarak ortaya çıkıyor:

https://www.facebook.com/sharer/sharer.php?u=http://example.com?share=1&cup=blue&bowl=red&spoon=green 

ilk & ve parametre cup (hem de diğer parametreler) facebook url parçası olarak yorumlanır.

& gibi özel karakterleri kodlar Kullanım encodeURIComponent():

İlgili konular