Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trying to use console of a new window

I'm beginner to learn JS and I am stuck with the following function.

I'm trying to open a new window and print in the console of the new window. My code is as follows:Can you please tell me where's the error ?

var newWindow = window.open("url");
newWindow.onload = function (newWindow) {
  newWindow.console.log("...something...");
}
like image 922
karan mirani Avatar asked Oct 20 '25 18:10

karan mirani


2 Answers

After the code

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

It should instantly open another window with "url" path. What happens after is field of work of "url" page. In this page you should have on document ready function which is similar to

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

Which could be simple jQuery function

$( document ).ready(function() {
    console.log( "ready!" );
});
like image 194
Mike Kor Avatar answered Oct 23 '25 08:10

Mike Kor


<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 a HTML file and run it, make sure pop-ups are not blocked.

like image 33
Himani Agrawal Avatar answered Oct 23 '25 07:10

Himani Agrawal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!