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
1 Answer
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
版权声明:本文标题:javascript - Facebook share image with target url - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745468484a2659637.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论