1

This jQuery script one creates a URL such as www.tumblr.com/like/fGKvAJgQ?id=16664837215 and then uses an iframe to send the 'like' with the above URL to Tumblr's servers.

$(document).on('click', '.like', function (event) {

    event.preventDefault();

    var command = $(this).hasClass('liked') ? 'unlike' : 'like',
        post = $(this).closest('.post'),
        oauth = post.find('.reblog').attr('href').slice(-8),
        id = post.attr('id'),
        likeUrl = 'http://www.tumblr.com/' + command + '/' + oauth + '?id=' + id;

    $('#like-it').attr('src', likeUrl);
    $(this).toggleClass('liked');

});

In the HTML this is used:

<article id="{PostID}">
    <a href="{ReblogURL}" class="reblog">reblog</a>
    <a href="#" class="like">like</a>
</article>

<iframe id="like-it"></iframe>

Is there a way to send this information to Tumblr instead of using the iframe with jQuery?

noob
  • 8,053
  • 4
  • 34
  • 64
Matt
  • 43
  • 4
  • this, possibly: http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain#3506306 ? – YS. Apr 20 '12 at 12:28
  • Both the websites are on the same domain though and I don't have access to the PHP. Unless I'm missing something? – Matt Apr 20 '12 at 12:30
  • @Matt Unless your script is running on a page on the `www.tumblr.com` domain, you're looking at a cross domain AJAX request. You also don't **need** access to the PHP, because for your purposes you don't really care about the response (other than that it indicates the request was successful, rather than returning an error status code). – Anthony Grist Apr 20 '12 at 12:33
  • Thanks, that got it working from the suggested question's selected answer. Sorry, didn't realize that sub-domains were counted as cross-domain requests. – Matt Apr 20 '12 at 12:45

1 Answers1

0

No that's not possible because of security reason.

Everywhere where you see a like button it's an iframe because you can't access an iframe by the parent page with JavaScript if the domain, protocol or port doesn't match.

This is because if a user visits your page you can force him to like millions of pages just by sending an ajax request to each page otherwise.

noob
  • 8,053
  • 4
  • 34
  • 64