Good day.

Please tell me where to dig: There is a page with posts. Under each post I use the "share" block from Yandex with standard settings. When scrolling to the end of the list with ajax, a few more posts are loaded, and so on. Starting with the 2nd batch of uploaded posts, the Yandex block stops loading.

P.S. Thanks in advance for the intention to help!

  • I wonder why on the page list of posts these buttons? After all, they will lead to the same page or not? Will he really share the link to the post? - arkadij_ok
  • I am in a loop through the same Ajax to them I hook up the parameter "data-url" with a unique link. On the page Navalny (navalny.com) is similarly done! - Dmitriy
  • And some mistakes start to fall out? I haven't mastered enough extrasensory skills yet, show me at least a console or a code - arkadij_ok
  • In general, it is worth reading the doc tech.yandex.ru/share/doc/dg/api-docpage - arkadij_ok
  • I read. Did not help. But another service, much lighter in size and with the placement of the script on its host, helped. share42 - Dmitry

1 answer 1

Ajax post uploading takes place for you with certain javascript-events. To one of these events ( ajax:success , for example) you need to bind a block initialization script with buttons:

 var share = Ya.share2('my-share', { content: { url: 'https://yandex.com' } // здесь вы можете указать и другие параметры }); 

Learn more: https://tech.yandex.ru/share/doc/dg/api-docpage/

In your case, each loaded post will already have a Yandex div -block with the necessary parameters in the data attributes. You will only need to receive data through them in the initialization script:

 var share = Ya.share2('my-share', { content: { image: $('#my-share').attr('data-image') url: $('#my-share').attr('data-url') ... } }); 

Where my-share is the block ID. In your case, the algorithm is as follows:

  • Ayaksovo get html with new posts
  • Browse all the Share blocks in them (for example, through the class ya-share2 )
  • Each block will recognize the ID (it must be assigned in advance and be unique) and run the initializer Ya.share2 ()