Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  129] [ 1]  / answers: 1 / hits: 19081  / 10 Years ago, wed, march 26, 2014, 12:00:00

Code 1:



<a id=button rel=nofollow href=http://www.facebook.com/share.php? onclick=return fbs_click() target=_blank>
<script>
function fbs_click() {
u=location.href;
t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),
'sharer',
'toolbar=0,status=0,width=626,height=436');

return false;
}




Here Title t is not working but i want to display custom title, summary, url and image so, I tried something like this



Code 2:



<a id=button          href=http://www.facebook.com/sharer.php?
s=100
&p[url]=<?php echo $pressurl;?>
&p[images][0]=http://myurl/images/linkedin_image.png
&p[title]=mytitle
&p[summary]=containsummary >


In both the cases nothing happened it automatically get some content (title,image,summary) from the above mentioned url and I want to display custom title,image and summary in facebook share page and i dono how to use og meta tag and what s=100 it means?..


More From » php

 Answers
11

Instead of using the sharer.php script on Facebook, you can use the Facebook JavaScript SDK to make a custom share dialog.



<!-- include Facebook JavaScript SDK -->

<!-- share link -->
<a href=# class=share-btn>Share to Facebook</a>

<script type=text/javascript>
function fb_share() {
// facebook share dialog
FB.ui( {
method: 'feed',
name: Your Page Title,
link: https://www.webniraj.com/link-to-page/,
picture: https://stackexchange.com/users/flair/557969.png,
caption: Some description here
}, function( response ) {
// do nothing
} );

}

// add click event to link using jQuery
$(document).ready(function(){
$('.share-btn').on( 'click', fb_share );
});
</script>


This will create a nice popup for sharing to Facebook, and you can easily change the title, description, and picture attributes in the JavaScript. Working demo available here.


[#71780] Monday, March 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cherish

Total Points: 734
Total Questions: 94
Total Answers: 86

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;