Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  92] [ 5]  / answers: 1 / hits: 67961  / 11 Years ago, sun, january 19, 2014, 12:00:00

I have a dynamic page with rewrited url. I want to add a facebook share button in that. So users click on the share button can share the page. But the facebook share developer page is asking for a specific url. Not sure how to share dynamically generated url.



Here some code i found to capture the url. But I dont know, how to include this in facebook code.



jQuery(document).ready(function() {
var href = jQuery(location).attr('href');
var url = jQuery(this).attr('title');
jQuery('#current_title').html(href);
jQuery('#current_url').html(url);
});


HTML Part of the Facebook Share Button



<div class=fb-share-button data-href=http://developers.facebook.com/docs/plugins/ data-type=button></div>





Kindly help



Many Thanks


More From » jquery

 Answers
4

This worked for me:



<script language=javascript>
function fbshareCurrentPage()
{window.open(https://www.facebook.com/sharer/sharer.php?u=+encodeURIComponent(window.location.href)+&t=+document.title, '',
'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');
return false; }
</script>


Then call the code with a link:



<a href=javascript:fbshareCurrentPage() target=_blank alt=Share on Facebook>Facebook</a>


If you want it to be a direct link instead of opening in a window, use this in the function:



window.location.href=https://www.facebook.com/sharer/sharer.php?u=+encodeURIComponent(window.location.href)+&t=+document.title;





Possible jquery solution:



<a class=fbsharelink data-shareurl=YOURLINK>Facebook</a>

$('.fbsharelink').click( function()
{
var shareurl = $(this).data('shareurl');
window.open('https://www.facebook.com/sharer/sharer.php?u='+escape(shareurl)+'&t='+document.title, '',
'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');
return false;
});

[#73072] Friday, January 17, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arturo

Total Points: 331
Total Questions: 99
Total Answers: 92

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
;