Good afternoon friends! Yandex has an API that allows you to place on the page a block "Share" with the counter LOCAL. Here is the code:

<script src="//yastatic.net/es5-shims/0.0.2/es5-shims.min.js"></script> <script src="//yastatic.net/share2/share.js"></script> <div class="ya-share2" data-services="vkontakte,facebook,odnoklassniki,moimir,gplus,twitter,linkedin" data-counter=""></div> 

This is how it looks like:
enter image description here

At the completion of the event "Share" you need to make the opening of a previously hidden link.

I tried through the script:

 $(".share-style-1").click(function() { $("#book_link").css("display", "inline-block"); $("#book_link_place").css("display", "none"); }); 

The link should not open until the user shares the page. Before this is just a paragraph. Markup:

 <p id="book_link_place" class="book_link_place">Здесь будет ссылка для скачивания</p> <br> <a href="http://profitmaster.bz/lessons/29_oshibok.pdf" id="book_link" class="book_link" target="_blank">Ссылка на книгу</a> 

Classes on social media icons are not amenable to processing. It will be great if someone helps to somehow handle the event.

    1 answer 1

    According to the instructions :

     Ya.share2('my-share', { hooks: { onready: function () { alert('блок инициализирован'); }, onshare: function (name) { alert('нажата кнопка' + name); } } }); 
     <script src="//yastatic.net/es5-shims/0.0.2/es5-shims.min.js"></script> <script src="//yastatic.net/share2/share.js"></script> <div id="my-share" data-services="vkontakte,facebook,odnoklassniki,moimir,gplus,twitter,linkedin" data-counter=""></div> 

    Handle onready remove the time you do not need, and in onshare put the code that should be executed when sharing.

    PS Here the script gives an error, but on https://jsfiddle.net/obbsvtjL/ it works without errors.

    • Very good! Forgot to add, you need to preserve cookies so that the user can refresh the page and the link for it is open. - Igor Voinov
    • @ IgorVoinov, so who is stopping you from saving the necessary cookies in the code that will be in place of alert('нажата кнопка' + name); from an example? - Visman
    • Tell me how to implement it? - Igor Voinov