The translation was generated automatically and may contain mistakes
Subscribe to Author
The widget will allow visitors to your site in one click to subscribe to the selected user or group. For example, by placing this widget under articles and materials on your site, it is easy to keep up-to-date information about authors.
Connecting Widget
To add a community VKontakte widget to your site, follow these steps:
Step 1. In the tag <head> On your website, add a link.. openapi.js :
<script src="https://vk.ru/js/api/openapi.js?169" type="text/javascript"></script>Step 2. Add code to the body of the site page to initialize the Open API:
<script type="text/javascript">
VK.init({
apiId: ?1?’АШ_API_ID,
onlyWidgets: true
});
</script>Read more about initialization of transport .
Add an element to the body of the page <div> , which will display comments, give it a unique id, and add a widget initialization code to it. For example:
<div id="vk_subscribe"></div>
<script type="text/javascript">
VK.Widgets.Subscribe('vk_subscribe');
</script>The above code adds a standard-looking widget. The width of the block will be selected automatically based on the size and position of the element with id="vk_subscribe" .
If your site is already in use Open API , adding a widget is even easier. Simply add widget initialization.
Additional settings
Method VK.Widgets.Subscribe Accepts the parameters:
- •
element_id(string), the mandatory parameter is the id of the element that will be the container for the block with the widget. Our default constructor uses a valuevk_subscribe. - •
options(object) — block options with widget. An object that can contain fields:- •
mode(integer), [0,1]is a widget type. Possible values:0The button,1The easy button,2- reference. - •
soft(integer), [0,1• Show the author. Possible values:0- display the author and the button,1Show only the button.
- •
- •
owner_id(integerA user or community identifier. The community ID must be negative, for example community VKontakte API It has ID-1.
Events
When you click on the “Subscribe” button, the widget transmits the event widgets.subscribed and when the user unsubscribes, the event widgets.unsubscribed . You can process these events using VK.Observer .
Example of use
<div id="vk_subscribe"></div>
<script type="text/javascript">
window.onload = function () {
VK.init({apiId: 111, onlyWidgets: true});
VK.Widgets.Subscribe('vk_subscribe', {mode: 1}, -1);
}
</script>Widget code
To add a widget to your site, simply copy the code to paste to the page you want to place the widget on.