javascript - Facebook share image with target url - Stack Overflow

i am currently developing a "share on facebook" feature but i don't know if it is possib

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'] ?>">

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745468484a4629021.html

相关推荐

  • javascript - Facebook share image with target url - Stack Overflow

    i am currently developing a "share on facebook" feature but i don't know if it is possib

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信