How to share your news on facebook without using a url
I am trying to include in my project a button that allows people to share an article on facebook.
I want the header and image of the news that users click to share in the facebook cover.
But I have no success, because in this project I show a summary of every news, and every news has a "Read full article" link and a "Share" link.
The problem is when I click "Read full article" my full article opens in fancybox without any url ... so this is my difficulty, how can I share my news on facebook without url?
I am really having difficulty understanding how each news item can be shared on Facebook because my news feed does not have a URL.
Do you see any way to achieve my goal?
This is my php:
//while exist news records in database
while ($result = $readNews->fetch(PDO::FETCH_ASSOC)){
echo '<article class="news">';
echo '<img class="img" src="'.BASE.'/uploads/news/'.$result['thumb'].'"/> ';
echo '<h2>'.$result['title'].'<br /></h2>';
echo '<span>'$result['date']).'</strong></span>';
echo '<p>'.$result['content].'
<a id="'.$result['id_news'].'"
class="fancybox" href="#window_fancybox'.$result['id_news'].'">
See full article </a>
</p>';
//my share link
echo '<a title="share" class="share" href="'.BASE.'">Share</a>';
//When I click in "See full article"
// it will open a fancybox with full article
echo '<div id="window_fancybox'.$result['id_news'].'" class="modal">';
echo '<h2>'.$resultt['title'].'</h2>';
echo '<span>'.$result['date'].'</span><br />';
echo '<img class="img" src="'.BASE.'/uploads/news/'.$result['thumb'].'"/>';
echo '<p>'.$result['content'].'</p>';
echo '<span class="close_fancy">Close modal</span>';
echo '</div>';
echo '</article>';
}
This is my script for facebook sharing:
$('.share').click(function(){
urlshare = $(this).attr('href');
alert(urlshare);
window.open('http://www.facebook.com/sharer.php?u=' +urlshare,'My website',"width=500,height=400,status=yes,toolbar=no,menubar=no,location=no");
return false;
})
You can see my example here: (my fancybox sharing window opens all white)
source to share
Something I want to know, are you using netau host or something? These domains and its subdomain are backed by facebook. And when you use it at https://www.facebook.com/sharer/sharer.php?u= it gives a blank page. I am writing these lines to know you, if you know it.
And, not much of a problem in what you want, as long as you are using a valid URL and not protected from facebook. You will not receive this blank page. But the problem with your idea is that facebook gets the title, description and "thumbnail of news" image from your page's html. So when all share buttons get the same title, description, and thumbnails. So to handle this, I suggest doing a small script behind the scenes on a separate page to handle this. If that makes sense, please tell me and I'll be happy to help.
source to share
go to facebook developers page and create app and add it in page body
<div id="fb-root">
</div>
<script> (function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=YOUR_APP_ID&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
</script>
replace YOUR_APP_ID with the app you get from facebook
And add this where you want the share button.
<div class="fb-like" data-layout="standard" data-action="like" data-show-faces="false"
data-share="true" width="100px">
Add meta tag for general image to be used by facebook
<meta property="og:image" content="http://www.example.com/images/logo.png" />
source to share
Your hosting doesn't seem to support sharing to Facebook. Shortcode link for sharing any Facebook links:
http://www.facebook.com/sharer.php?u= &t=
where u
is url
, and t
are title
pages.
Now when I try to share my article on Facebook with the following link:
https://www.facebook.com/sharer/sharer.php?u=http://ei-test.netau.net/&t=United%20FC%20win%20the%20game
nothing appears. But if you try another link like:
https://www.facebook.com/sharer/sharer.php?u=http://www.infismash.com/hover-social-buttons-wordpress/&t=United%20FC%20win%20the%20game
it clearly shows the Facebook sharing option.
Basically, I think your problem will be solved if you try a different host. Also, keep in mind that many Facebook does not support many free hosting sites.
Since you want to share an individual modal windows
one, what you could do is try to provide each modal with an ID , eg #identifier-1.fancybox-overlay .fancybox-overlay-fixed
. Look at id-1 . This one 1
will be id
for every post. This way, when someone clicks on your link, for example http://ei-test.netau.net/#identifier-1
, the window will open with the modal active.
source to share
Facebook sharer.php is deprecated, you will need to use their "Access Dialog" which requires you to set the facebook APP id for your domain.
https://www.facebook.com/dialog/share?
app_id=145634995501895
&display=popup
&href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2F
&redirect_uri=https%3A%2F%2Fdevelopers.facebook.com%2Ftools%2Fexplorer
However, this method allows you to get the metadata from the URL you provided, you can use their JavaScript API to provide your resource with a unique title, description, and URL.
Link: https://developers.facebook.com/docs/sharing/reference/share-dialog#redirect https://developers.facebook.com/docs/javascript/quickstart/v2.1
source to share