[英]Facebook like/share current URL
I have been trying to solve this for a few days now. 我已经尝试解决几天了。 Basically I have a like/share button on my site generated using the facebook developer tool. 基本上,我的网站上有一个使用“ Facebook开发者”工具生成的“喜欢/分享”按钮。 So it is very standard. 因此,这是非常标准的。 But I can't get it to like/share the current URL. 但是我无法让它喜欢/共享当前URL。
<div class="fb-like col-xs-offset-1" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
What I have tried: 我试过的
1) Using data-href =" <%= Request.Url.AbsoluteUri %> "
1)使用data-href =" <%= Request.Url.AbsoluteUri %> "
2) Setting data-href
using javascript using window.location
2)使用window.location
使用javascript设置data-href
3) Leaving data-href
empty. 3)将data-href
留空。 Now this is said to work, but it does not for me. 现在,据说这行得通,但对我来说不行。 However I suspect this is because I am running on localhost, could that be why? 但是我怀疑这是因为我在本地主机上运行,这可能是为什么吗?
When I try these methods it gives me this link before I get to the actual share-window: 当我尝试这些方法时,在进入实际的共享窗口之前,它会为我提供此链接:
https://www.facebook.com/v2.2/plugins/like.php?action=like&app_id=78205603350&channel=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter%2FrFG58m7xAig.js%3Fversion%3D41%23cb%3Df2283ae550ed898%26domain%3Dlocalhost%26origin%3Dhttp%253A%252F%252Flocalhost%253A59928%252Ff3ee4865310c9fa%26relation%3Dparent.parent&container_width=1237&href=http%3A%2F%2Flocalhost%3A59928%2FDefault&layout=standard&locale=en_US&sdk=joey&share=true&show_faces=true
And then when I press next and come to the actual sharing-window it tries to share "www.facebook.com" 然后,当我按下一步并进入实际的共享窗口时,它将尝试共享“ www.facebook.com”
1) Must be <%= 1)必须为<%=
data-href="<%=Request.Url.AbsoluteUri%>"
2) You could do 2)你可以做
<div id="sharebutton"
...
window.onload = function () {
var currentUrl = window.location.href;
document.getElementById("sharebutton").setAttribute("data-href", currentUrl);
}
-- or using jquery
jQuery(document).on('ready', function($){
var url = window.location;
$('.fb-like col-xs-offset-1').attr('data-href', url);
});
3) Leaving data-href "" blank worked before v2.0 of social plugin 3)在社交插件v2.0之前将data-href“”留空
You can't share localhost. 您不能共享本地主机。 You need to test your share-button on production server where you would have real URL 您需要在生产服务器上测试您的共享按钮,在该服务器上您将拥有真实的URL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.