Ways To Open URL In New Window

In this article, I will explain the ways to open an URL in a new Window. So let’s start the tutorial.

Ways To Open URL In New Window

There are 3 ways, to use them we can open the URL in a new Window.

  1. Using window.open() Method
  2. Using Anchor Tag
  3. Using input tag

let’s start one by one.

1. Using window.open() Method

This method is used to open a new browser window or tab based on the browser setting and provided parameters.

Syntax:

window.open(URL, name, specs, replace)

All the parameters from the above syntax are optional. But If you want to open an URL then pass the URL of the page into the URL parameter. Check the below example with your console.

window.open("https://www.thecodehubs.com");

2. Using Anchor Tag

Using the <a> tag we can open an URL in a new window. Check the below code.

<a href="https://www.thecodehubs.com">The Code Hubs</a>

3. Using input Tag

Using input tag and window.open() method, we can open an URL into another tab. See the below example.

<input type="button" value="button name" onclick="window.open('https://www.thecodehubs.com')" />

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories