It is impossible to add a video using YouTube link for VKontakte (in automatic mode, using javascript or jQuery). Added YouTube link code to the right place (Video Records page of VKontakte):

jQuery("input#video_external_link").val("ссылка видео ютуба"); 

or with javascript:

 document.querySelectorAll("input#video_external_link")[0].value = "ссылка видео ютуба" 

But nothing happens, all the detailed information about the YouTube video (with the add button for VKontakte), which I want to add, should have been released.

I tried jQuery("body *").focus().blur(); - works only if the mouse is in focus in the current browser, and if it is outside the browser, then nothing happens again, I want it to always work.

Here is an example of how it happens:

If manually:

enter image description here

If using javascript:

Code:

enter image description here

Result:

enter image description here

In the last screenshot you can see that it does not respond to the link that was set using the code. What is missing here to make it work?

    2 answers 2

    It works like this for me

     const el = document.querySelector('#video_external_link'); el.value = 'https://www.youtube.com/watch?v=RbESB3qHWOw'; triggerEvent(el, 'blur'); 

      So works

       var vid = document.getElementById("video_external_link");//получаем элемент vid.value = "ссылка";//записываем ссылку var foc = new Event("focus");// содаем событие фокус var bl = new Event("blur"); // создаем событие блюр vid.dispatchEvent(foc); //фокусим input vid.dispatchEvent(bl); //вызываем событие blur