admin管理员组

文章数量:1426975

i am currently developing a "share on facebook" feature but i don't know if it is possible. The user should have a share button on a webpage, but with the button he doesn't share the page he shares an image.

When another user sees the image on facebook, and clicks on it, he should get redirected to a url i can choose.

i can't simply share the whole site and use open graph tags because the page where the share button is located is on a private area of the website and can only be accessed when you log in.

this whole thing must be done via javascript on client side. perfect solution for me would be if i can use sth. like

FB.ui(..., {image: 'path to image', url: 'url to call when image is clicked on fb'},... );

Any ideas?

i am currently developing a "share on facebook" feature but i don't know if it is possible. The user should have a share button on a webpage, but with the button he doesn't share the page he shares an image.

When another user sees the image on facebook, and clicks on it, he should get redirected to a url i can choose.

i can't simply share the whole site and use open graph tags because the page where the share button is located is on a private area of the website and can only be accessed when you log in.

this whole thing must be done via javascript on client side. perfect solution for me would be if i can use sth. like

FB.ui(..., {image: 'path to image', url: 'url to call when image is clicked on fb'},... );

Any ideas?

Share Improve this question asked Apr 14, 2015 at 11:37 coRcoR 251 gold badge2 silver badges5 bronze badges 1
  • You either share a link, or you don’t. You can’t have a normal photo arbitrarily link to just anywhere you want. “because the page where the share button is located is on a private area of the website and can only be accessed when you log in” – it doesn’t matter where the share button is located, it matters what URL you share … so share one that is outside of the private area. – C3roe Commented Apr 14, 2015 at 15:29
Add a ment  | 

1 Answer 1

Reset to default 2
<a onclick="shareit()">Share on facebook</a>

<script type="text/javascript">
function shareit(){
var url="http://www.example."; //Set desired URL here
var img="http://www.example./example.jpg"; //Set Desired Image here
var totalurl=encodeURIComponent(url+'?img='+img);

window.open ('http://www.facebook./sharer.php?u='+totalurl,'','width=500, height=500, scrollbars=yes, resizable=no');

}
</script>

Besides when you pass OG image as querystring to the target URL, in the target URL you will need a code which retrievs the image address and set it as OG image. So in target URL you will need this line:

<meta property="og:image" content="<?php $_GET['img'] ?>">

本文标签: javascriptFacebook share image with target urlStack Overflow