Internet pages comprise exterior hyperlinks that open URLs in a brand new tab. For instance, Wikipedia articles present hyperlinks to open the reference websites in a brand new tab. That is completely for newcomers.
There are 3 ways to open a URL in a brand new tab.
- HTML anchor tags with goal=_blank attribute.
HTML anchor tags with goal=_blank attribute
<a href="https://www.phppot.com" goal="_blank">Go to Phppot</a>
The above line makes opening a URL and focuses the newly opened tab.
- Create an anchor tag (<a>) by utilizing the createElement() perform.
- Units the href and the goal properties with the reference of the hyperlink object instantiated in step 1.
- Set off the press occasion of the hyperlink component dynamically created by way of JS.
var url = "https://www.phppot.com"; var hyperlink = doc.createElement("a"); hyperlink.href = url; hyperlink.goal = "_blank"; hyperlink.click on();