Javascript open new tab

A simple but useful task!

To open a new tab in JavaScript, you can use the window.open() method. Here's the basic syntax:

window.open(url, "_blank");

Where:

Here's an example:

<button onclick="openNewTab()">Open New Tab</button>

<script>
  function openNewTab() {
    window.open("https://www.example.com", "_blank");
  }
</script>

When you click the button, the openNewTab() function will be called, which will open a new tab with the URL https://www.example.com.

You can also specify additional options, such as:

Note that the window.open() method returns a reference to the new window, which you can use to interact with the new tab.

Alternatively, you can use the window.open() method with the target attribute set to _blank in an anchor tag:

<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank">Open New Tab</a>

This will also open a new tab when the link is clicked.