Answer the question
In order to leave comments, you need to log in
VK API. How to get the id of the "Like" widget when liking?
Hello!
I've been struggling with the following problem for a few days now, which I can't seem to solve.
There is a page with an arbitrary number of VK "Like" widgets. For example, like this:
<div id="widget_1"></div>
<script>VK.Widgets.Like("widget_1", {type: "vertical", pageURL: 'url_1'}, 1);</script>
<div id="widget_2"></div>
<script>VK.Widgets.Like("widget_2", {type: "vertical", pageURL: 'url_2'}, 2);</script>
VK.Observer.subscribe("widgets.like.liked", function f(likesNum)
{
alert ("Вы лайкнули! Количество лайков: " + likesNum);
});
Answer the question
In order to leave comments, you need to log in
Despite the fact that the VKontakte request was answered in the negative:
Hello Peter!
Sorry for the long wait.
Unfortunately, there is no way to implement your idea at the moment. The developers promised to make the observer accept the page_id parameter.
VK team.
VK.Observer.subscribe("widgets.like.liked", function f(likes_num,vk_widget_num) {
/* ... */
});
<div id="widget_1" class="like_widget" data-widget-number="1"></div>
<script>VK.Widgets.Like("widget_1", {type: "vertical", pageURL: 'url_1'}, 1);</script>
<div id="widget_1" class="like_widget" data-widget-number="2"></div>
<script>VK.Widgets.Like("widget_2", {type: "vertical", pageURL: 'url_2'}, 2);</script>
VK.Observer.subscribe("widgets.like.liked", function f(likes_num,vk_widget_num)
{
var widget_id = $('.like_widget[data-widget-number=' + vk_widget_num + ']').attr('id');
alert ("Вы лайкнули! Был нажат виджет с ID: " + widget_id + ". Количество лайков: " + likes_num);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question