L
L
lsa4132015-10-30 20:55:42
In contact with
lsa413, 2015-10-30 20:55:42

Asynchronous initialization of Vkontakte api and VK.Auth.getLoginStatus() function?

Hello!
There was such a question.
Let's say I'm doing asynchronous initialization of the VK application by inserting the code at the beginning of the body tag:

window.vkAsyncInit = function() {
        VK.init({
            apiId: 5105632
        });
    };

    setTimeout(function() {
        var el = document.createElement("script");
        el.type = "text/javascript";
        el.src = "//vk.com/js/api/openapi.js";
        el.async = true;
        document.getElementById("vk_api_transport").appendChild(el);
    }, 0);

At the same time, I need the method to work first when the page loads:
VK.Auth.getLoginStatus()
The problem is that, since the initialization is asynchronous, the VK.Auth.getLoginStatus() method fires before the response from "/ /vk.com/js/api/openapi.js".
The question is how to force the VK.Auth.getLoginStatus() method to wait until the initialization has passed and only then be executed?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question