Create new window object javascript

In JavaScript, you can create a new window object using the window.open() method or by creating a new Window object using the Window constructor.

Method 1: Using window.open()

var newWindow = window.open('about:blank', '_blank', 'width=400,height=300');

This will create a new window with the specified dimensions and URL (about:blank is a special URL that opens a blank page).

Method 2: Using the Window constructor

var newWindow = new Window();

This will create a new Window object, but it will not be associated with a physical window on the screen. You will need to use the document property to access the document object of the new window.

Example: Creating a new window with a specific URL and dimensions

var newWindow = new Window();
newWindow.document.write('<html><body>Hello World!</body></html>');
newWindow.document.title = 'New Window';
newWindow.width = 400;
newWindow.height = 300;
newWindow.left = 100;
newWindow.top = 100;

This will create a new window with the specified dimensions and URL, and set the title and position of the window.

Note: In modern browsers, the Window constructor is not supported and will throw an error. Instead, you should use the window.open() method to create a new window.

Example: Creating a new window using window.open()

var newWindow = window.open('about:blank', '_blank', 'width=400,height=300');

This will create a new window with the specified dimensions and URL, and will be associated with a physical window on the screen.