Trying to use a new window console

I am starting to learn JS and I stick to the following function.

I am trying to open a new window and print a new window in the console. My code is as follows: Could you tell me where the error is?

var newWindow = window.open("url");
newWindow.onload = function (newWindow) {
  newWindow.console.log("...something...");
}
+4
source share
4 answers

After the code

var newWindow = window.open("url");

It should immediately open another window with a "URL". What happens after the section of the page "URL". On this page you should have a document ready function that is similar to

newWindow.onload = function (newWindow) {
    newWindow.console.log("...something...");
}

What could be a simple jQuery function

$( document ).ready(function() {
    console.log( "ready!" );
});
+1
source
<html>
<script>
function myFunction() {
var myWindow = window.open("", "MsgWindow", "width=200, height=100");
myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
}
myFunction();
</script>
</html>

Write this code in the HTML file and run it, make sure that the pop-ups are not blocked.

+1

, , . , javascript window 1, window 2. window 2 js onload. onload window 2 window 1 . , window 1 window 2.

. fiddle window 1.

+1

( URL), :

var newWindow = window.open("");
newWindow.console.log("test");

: https://jsfiddle.net/8p2fk4j0/ ( )

0
source

Source: https://habr.com/ru/post/1622579/


All Articles