Reputation: 4047
I am trying to find a way to take the value of share social button see: http://www.1stwebdesigner.com/wordpress/wordpress-plugins-social-sharing/ Buttons are located on left side of the page.
Now I thought maybe using JavaScript on document ready to take the value of the specific span//div. however they are in a iframe and it seem to not work:
here is what I have so for:
<iframe id="something_iframe"
src="http://www.facebook.com/plugins/like.php?href=http://www.freelancer.com/projects/myskills.php&send=false&layout=button_count&width=100&show_faces=false&action=like&colorscheme=light"
scrolling="no" frameborder="0"
style="border:none; overflow:hidden; width:100px; height:21px;"
allowTransparency="true">
</iframe>
<div id="something">
</div>
<script>
var $j = jQuery.noConflict();
$j(document).ready(function() {
$j("#something").text($j(".pluginCountTextDisconnected").text());
});
</script>
I think however even if this JavaScript way would work its still messy and there probably a better way in PHP API or something.
Upvotes: 2
Views: 508
Reputation: 443
I don't know if this is something that you might be looking into, but I wanted to add this answer in case anyone happens to look up a similar question.
If what I understand from the question is right, you want a way to get the count of shares / likes / anything from social plugins and use that number.
While working on a similar problem, I've found the following plugin: Sharrre
It avoids the same origin policy
issue by calling some of the APIs from PHP using CURL
, and some straight from Javascript. It already is set up for a couple of the most used social sites and it's pretty easy to add other sites if you want to.
It does have the disadvantages that you have to manually add the link you want to search the share count for, and that on the server side it's sometimes a little laggy (due to response times from the social sites). Also, with every API change from social sites you use, you must check that it's still working as it should.
Please know that I don't have any affiliation to the plugin / site, I just used the plugin and it really helped me, and I hope it will help others as well.
Upvotes: 0
Reputation: 23648
This is simply not possible due to the same origin policy
because these spans are loaded inside a iFrame that has gets loaded from a different page than yours.
When the same origin policy is active you cannot manipulate the contents of the iFrame or access it. There may be some hacks around this, but I'd suggest you look at the API of twitter and Facebook as they are likely to expose the like/retweet count through the API.
This also has the benefit of not breaking whenever Twitter/Facebook changes something to their share buttons. These are not meant to be a public interface so they are free to change their code anytime.
Update: After looking a bit more at the Site markup it seems you can access the Google+ button as it is placed in the HTML of the side and not inside an iFrame, but Facebook and Twitter run their widget button inside an iFrame where you don't have access to.
Upvotes: 2