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...");
}
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!" );
});
<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With