YouTube Icon

How to Open a Link in a New Window And Print New Window Using JavaScript

How to Open a Link in a New Window And Print New Window Using JavaScript

JavaScript is a useful way to open a link in a new window because you control how the window will look and where it will be placed on the screen by including specifications.

Syntax for the JavaScript Window Open() Method
To open a URL in a new browser window, use the Javascript open() method as shown here:, name, specs, replace)

URL Parameter

Beyond opening a window, you can also customize each of the parameters.

For example, the code below opens a new window and specifies its appearance using parameters.

Enter the URL of the page you want to open in the new window. If you don't specify a URL, a new blank window opens:"", "_blank");

Name Parameter

The name parameter sets the target for the URL. Opening the URL in a new window is the default and is indicated in this manner:

  • _blank. Opens a new window for the URL.
  • Other options you can use include:
  • _self. Replaces the current page with the URL.
  • _parent. Loads the URL into the parent frame.
  • _top. Replaces any framesets that are loaded.


The specs parameter is where you customize the new window by entering a comma-separated list with no white spaces. Choose from the following values.

  • height=pixels. This specification sets the height of the new window in pixels. The minimum value that can be entered is 100.
  • width=pixels. This sets the width of the new window in pixels. The minimum value is 100.
  • left=pixels. This spec sets the left position of the new window. No negative values can be entered.
  • top=pixels. This sets the top position of the new window. Negative values cannot be used.
  • menubar=yes|no|1|0. Use this spec to indicate whether or not to display the menu bar.
  • status=yes|no|1|0. This indicates whether or not to add a status bar.

Some specifications are browser-specific:

  • location=yes|no|1|0. This spec indicates whether or not to show the address field. For Opera browser only.
  • resizeable=yes|no|1|0. Determines whether or not the window can be resized. For use with IE only.
  • location=yes|no|1|0. Indicates whether or not to display scrollbars. Compatible with IE, Firefox, and Opera only.
  • toolbar=yes|no|1|0. Determines whether or not to show the browser toolbar. Compatible with IE and Firefox only.


This optional parameter has only one purpose — to specify whether the URL that opens in the new window replaces the current entry in the browser history list or appears as a new entry. 

  • When true, the URL replaces the current browser entry in the history list.
  • When false, the URL is listed as a new entry in the browser history list.

Print New Window

Page print in JavaScript is a simple code in JavaScript used to print the content of the web pages.
The print() method prints the contents of the current window.
It basically opens Print dialog box which lets you choose between various printing options.


var myWindow="", "_blank");

Final Result

Author Biography.

Lokesh Gupta
Lokesh Gupta

Overall 3+ years of experience as a Full Stack Developer with a demonstrated history of working in the information technology and services industry. I enjoy solving complex problems within budget and deadlines putting my skills on PHP, MySQL, Python, Codeigniter, Yii2, Laravel, AngularJS, ReactJS, NodeJS to best use. Through Knowledge of UML & visual modeling, application architecture design & business process modeling. Successfully delivered various projects, based on different technologies across the globe.

Join Our Newsletter.

Subscribe to CrowdforThink newsletter to get daily update directly deliver into your inbox.

CrowdforGeeks is where lifelong learners come to learn the skills they need, to land the jobs they want, to build the lives they deserve.


CrowdforThink is a leading Indian media and information platform, known for its end-to-end coverage of the Indian startup ecosystem.


Our mission is "Har Koi Dekhe Video, Har Ghar Dekhe Video, Ghar Ghar Dekhe Video" so we Provide videos related to Tutorials, Travel, Technology, Wedding, Cooking, Dance, Festivals, Celebration.

Apna Video Wala

News & Blogs


An In-Depth Guide On Choosing Best Frontend Fra...

Since the outbreak of COVID-19, business operations have been moved online to make ends meet....


What is the Difference Between =, ==, and === i...

What is = in JS?  Equivalent to (=) is a task administrator, which sets the variable on t...


JavaScript Mobile Frameworks worth considering ...

When it comes to startups entering the business arena, they have very tough competition. This is ...

Top Authors

Lamia Rochdi is the Marketing Manager at Bell Flavors & Fragrances EMEA. A successful family-...

Lamia Rochdi

I’m Mertin Wilson a technician in a camera company and certified expert of different P...

Mertin Wilson

Zakariya has recently joined the PakWheels team as a Content Marketing Executive, shortly after g...

Zakariya Usman

Pankaj Singh is a Senior Digital Marketing Consultant with more than 2 years of experience in SEO...

Pankaj Singh

Our Client Says

WhatsApp Chat with Our Support Team