2013-06-02 58 views
0

我使用使用encodeURIComponent感到困惑傳遞http://在一個字符串的URL,因爲它是被剝離到URL進行編碼錯誤

http%3A%2F%2F 

我試過。(HTTP://)

,但沒有工作,要麼.. 我想要的網址進入這裏:

https://www.facebook.com/sharer/sharer.php?url= 

這裏是我的代碼不工作:

$(document).on('click', '.fb', function(e) { 

var findfb = $('.fb').parent().parent().parent().find(".zoomy").attr("src"); 

var facebook_url = 'http://www.facebook.com/sharer.php?url=http://www.site.com/folder1/'+encodeURIComponent(findfb)+ 
    '&title='+encodeURIComponent('title of page'); 

    window.open(facebook_url); 


}); 
+0

encodeURIComponent方法應該打開HTTP://部分爲你貼上什麼。 decodeURIComponent應該不轉換它。你如何將URL傳遞給Facebook分享器API? –

+1

這完全正確。你有什麼問題? – SLaks

+0

我更新了我的源代碼。 – Blynn

回答

1

只要做到這一點就這麼簡單:

var facebook_url = 'http://www.facebook.com/sharer.php?url=' + encodeURIComponent('http://www.site.com/folder1/' + findfb +'&title=' + 'title of page'); 
0

var facebook_url = 'http://www.facebook.com/sharer.php?url=' + encodeURIComponent('http://www.site.com/folder1/' + findfb) + '&title=' + encodeURIComponent('title of page');

+0

這也是錯誤的。 – SLaks