V
V
Vlad2016-04-01 13:03:20
Google
Vlad, 2016-04-01 13:03:20

How to call a Javascript event for the Share widget from Yandex?

Widget from Yandex "Share" buttons: https://tech.yandex.ru/share/
It has an API: https://tech.yandex.ru/share/doc/dg/api-docpage/
.. which reports about onshare and onready events
I'm a bit stupid in javascript.. please tell me where and how to register the "onshare" event so that when it is done, it gives out alert("OK") ??

<div onshare="alert("Ок");" class="ya-share2" data-services="vkontakte,twitter,facebook,gplus" data-counter></div>

not? :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Faliah, 2016-04-01
@Sc0undRel

Everything works fine even with a simple ctrl-c+ctrl-v
Copied from the official documentation
Essentially:

  1. throw an element on the page, suppose
    <div id="ya_share" class="ya-share2" data-services="vkontakte,twitter,facebook,gplus" data-counter></div>

  2. initialize the widget:
    Ya.share2('#ya_share', {
        hooks: {
            onready: function () {
                alert('блок инициализирован');
            },
    
            onshare: function (name) {
                alert('нажата кнопка' + name);
            }
        }
    });

  3. ...Profit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question