Last Updated : Jan 1, 2023
The window.open() method opens a new browser window or a new tab depending on our browser setting and the parameter values.
The document.write() method writes a string of text to a document stream opened by document.open().
Here in script we defined variable ‘win’ for refer window object. Using variable ‘win’ we defining new tab size of ‘width to 800, height to 600’ and toolbar settings to ‘0’.
So when user loads this file on browser new tab will open as per we given size and specifications then we are writing some content on that tab so we defined document.write() with ‘win’.
Within that we setting tab title and contents for tab.
<!DOCTYPE html> <html> <head> <title>New Tab With Content</title> </head> <body> <script> var win=window.open('','',width=800,height=600,toolbar=0); win.document.write('<title>Print Report</title>Hello Everyone Welcome to New Window'); </script> </body> </html>
- <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
- The<html> tag is used to indicate the beginning of HTML document.
- As above shown <head> tag is contains information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
- Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
- <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
- In <script> we defined window.open() method with window size specifications as ‘width and height to 800,600’ then we setting toolbar to none and those referred by variable ‘win’.
- Using document.write() method we sets tab title as ‘Print Report’ and inserted content ‘Hello Everyone Welcome to New Window’ on tab by adding this with object ‘win’.
- So when user loads this file new window tab will opened with defined size and specifications with contents.
- We can also modify contents or title, size anything with your own wish those are not mandatory specifications.
- Both </body>, </html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.
When we executing this program on browser we can see new window tab will open with respect to defined window size and inserted contents.
We can also open new tab with blank space and we can create with customized specifications later we will see about that in future.