A
A
Arti-Jack2018-04-28 00:05:41
JavaScript
Arti-Jack, 2018-04-28 00:05:41

Why does the VK.init initialization problem occur?

Good day to all.
I can't understand why VK.init doesn't work.
And I'm not sure yet, but I had to do it right. At the beginning, I went to the "create an application" item. I chose the item "Standalone-application". Next, I set up the website address and base domain. I used github pages.
And then, in the end, I wrote the following code (as in the documentation):

<!DOCTYPE html>
<html>
<head>
  <title>Test VK API</title>
  <script src="https://vk.com/js/api/openapi.js?153" type="text/javascript"></script>
<script type="text/javascript">
  VK.init({
    apiId: 	MY_ID
  });
</script>
</head>
<body>

</body>
</html>

Where MY_IDis the id of my application.
I go to the github pages site of my repository and see an error.
openapi.js?153:434 Uncaught TypeError: Cannot read property 'insertBefore' of undefined
    at Object.VK.init (openapi.js?153:434)
    at (index):8

index 8 is the initialization.
VK.init:
root = document.getElementById(VK._rootId);
    if (!root) {
      root = document.createElement('div');
      root.id = VK._rootId;
      body = document.getElementsByTagName('body')[0];
      body.insertBefore(root, body.childNodes[0]);
    }

Basically, I don't understand what I'm doing wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
newaitix, 2018-04-28
@Arti-Jack

Translation of the error "cannot read the insertBefore property of the bady variable"
File openapi.js line 153 character 434

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question