Group widget

With this widget, you can advertise your group on Odnoklassniki. It will allow your website visitors to join just in one click.

Your group should be open to joining.

Widget settings

Group ID
Width
Height

Result

How to get the ID of group:

  1. You must be an administrator of the group.
  2. Log in to your group.
  3. Left under the avatar group in the menu there is an option “Settings.” Check it.
  4. At the bottom of the page that appears find the label “Group id: “.
  5. Copy the ID and paste it into the widget embed code.

When you embed multiple widgets on a single page you can use the code:

!function (d, id, did, st) {
  var js = d.createElement("script");
  js.src = "https://connect.ok.ru/connect.js";
  js.onload = js.onreadystatechange = function () {
  if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") {
    if (!this.executed) {
      this.executed = true;
      setTimeout(function () {onOkConnectReady()}, 0);
    }
  }}
  d.documentElement.appendChild(js);
}(document);
function onOkConnectReady() {
  OK.CONNECT.insertGroupWidget("mineGroupWidgetDivId","50582132228315","{width:250,height:335}");
  OK.CONNECT.insertShareWidget("mineShareWidgetDivId","https://apiok.ru","{width:125,height:25,st:'oval',sz:12,ck:1}");
}

You can track event on page with widgets by the following javascript code:

function listenForShare() {
    if (window.addEventListener) {
        window.addEventListener('message', onShare, false);
    } else {
        window.attachEvent('onmessage', onShare);
    }
}

function listenForJoin() {
    if (window.addEventListener) {
        window.addEventListener('message', onJoin, false);
    } else {
        window.attachEvent('onmessage', onJoin);
    }
}

function onShare(e) {
    var args = e.data.split("$");
    if (args[0] == "ok_shared") {
        alert(args[1]);
    }
}

function onJoin(e) {
    var args = e.data.split("$");
    if (args[0] == "ok_join") {
        alert(args[1]);
    }
}

listenForShare();
listenForJoin();