0

I want to use current page url in data-href="".... i want to use somthing like this <data-href="javascript:window.location.href"> but it is not working.

<div class="fb-like" data-href="" data-layout="standard" data-action="like" data-size="small" data-show-faces="true" data-share="true"></div><br>                   
                    </div>
1
  • 1
    The current URL is /. It's the path relative to where you are. Commented Aug 22, 2017 at 11:54

1 Answer 1

1

Try this :

$(function () {

   $('.fb-like').attr('data-href', location.href);
            or 
   $('.fb-like').data('href', location.href);

  });
Sign up to request clarification or add additional context in comments.

1 Comment

document.querySelectorAll('.fb-like').forEach( fb => fb.dataset.href = location.href); as a no-library DOM 'plain' JavaScript solution. Although depending on the browser the use of forEach() with a NodeList, or Arrow functions, might cause issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.