1

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. So it is very standard. But I can't get it to like/share the current 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 %> "

2) Setting data-href using javascript using window.location

3) Leaving data-href empty. 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"

Rodal
  • 131
  • 1
  • 1
  • 9

1 Answers1

0

1) Must be <%=

data-href="<%=Request.Url.AbsoluteUri%>"

2) You could do

<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

You can't share localhost. You need to test your share-button on production server where you would have real URL

user2316116
  • 6,726
  • 1
  • 21
  • 35
  • Hi, As I said in my question I have tried using both those methods. My bad on forgetting "=" tho. Didnt copy the code just wrote it in manually. Will edit – Rodal Mar 05 '15 at 07:30
  • 1) So, if used ´data-href="<%=Request.Url.AbsoluteUri%>"´ go to the source code and see generated code. 2) show you code – user2316116 Mar 05 '15 at 07:32
  • I have edited a bit, maybe this will tell something more. Thanks for trying to help – Rodal Mar 05 '15 at 07:36
  • Maybe that link is trying to tell me that it is trying to share localhost but it cant? and therefore it changes the share to faceook.com – Rodal Mar 05 '15 at 07:43
  • You can't share localhost. You need to test your share-button on production server where you would have real URL – user2316116 Mar 05 '15 at 07:59