Answer the question
In order to leave comments, you need to log in
Is there an analogue of mailru.app.events.like for websites?
Social networks are a great marketing tool, but sometimes they don't want to give their features the opportunity to save the user. I have a task before me: there is an online store, there are “like” buttons (quite standard ones, i.e. not in the form of your own bicycle, which asks for permission to add a like on click, but ordinary such buttons). It is necessary to intercept the like and unlike event, namely, on clicking "like" through ajax, load a one-time discount coupon code and show it to the user.
If the store were an application, then everything would be simple - there is a mailru.app.events.like event, but there is no such event for sites. Like/dislike create cookies, but they are for the *.mail.ru domain. The buttons themselves are in an iframe, the content of which cannot be retrieved either.
Perhaps someone faced a similar task - tell me how this can be done and whether it can be implemented.
Moral side of the issue: social networks are NOT against incentivizing clicks on “likes” if everything is fair to the user.
Answer the question
In order to leave comments, you need to log in
If, for example, using jQuery, then you can do this:
$("iframe").contents().find("#like-button").click(function() {
//your code
});
In my case, there were about a dozen like buttons on the page and it was necessary to understand which one was clicked on.
I caught that the widget inserts an iframe with buttons before .
They also have click event catchers:
http://api.mail.ru/2012/01/share_and_event/
they give result.id and so the iframe on the page is generated with this id. In total, I caught the value I needed like this:
<a target="_blank" class="mrc__plugin_uber_like_button"
data-good-id="МойИтемАйди"
href="http://connect.mail.ru/share?share_url=<?=$urly?>"
data-mrc-config="{'type' : 'small', 'caption-mm' : '2', 'caption-ok' : '1', 'width' : '50px', 'nc' : '1', 'nt' : '1'}">Нравится
mailru.loader.require('api', function(){
mailru.events.listen(mailru.plugin.events.liked, function(result, params, elsevar){
good_id = $("#"+result.id).parent().next().attr("data-good-id");
});
mailru.events.listen(mailru.plugin.events.unliked, function(result){
// console.log(result.type);
// Анлайки всё равно не пашут :)
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question