Good day

I just wanted to know, can I run the event so

for example >>

window.open("http://google.ru"); 

but I suppose I need not quite a link

I need for example like this,

this is part of the code, running in javascript another javascript

 <script> window.open();{сторонний javascript }; window.focus(); </script> 

I haven’t checked the full code yet. Can it be done like this or it won't work? so that I don’t have to dig too much and do not waste time, I want to know, I study and collect knowledge by poking trial and error.

  • one
    it is also usually the case that triggers <script> events window.onload = function () {another javascript}; </ script> <iframe src = " example.com " style = "height: 60px"> </ iframe> <img src = " js.cx/clipart/yozhik.jpg?speed=1 "> - Bor
  • 2
    “you can run an event like this” - the programmer’s head to think, the brains to think, and the fingers to clearly explain to StackOverflow what he needs. - Igor
  • Can't open() accept a callback as an argument? - Byulent
  • @Byulent, no, he doesn’t need it, he returns the open window - Grundy

2 answers 2

In the window opened by the script, you can not execute the code.

This restriction is imposed for security reasons.

  • ... if they have different origin - Pavel Mayorov
 Пример использования внешнего js скрипта: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> Пример использования функции jquery: <script> function check(invalue) { if (invalue.length > 40) $(.input).hide(); } </script> При подключении внешнего js-файла все его функции становятся доступными: <script> check(invalue); </script> Пример использования функции js внутри тега-строки <input>(получает значение строки при нажатии клавиши в данном элементе): <input type="text" name="value" class="input" onkeyup="check(this.value)" />