In HTML we use <a>
tag for a hyperlink to another page. For Open URL in New Tab Using JavaScript we use <a>
tag target
attribute.
In HTML <a> tag’s target attribute provides a simple way to open a new tab or new window of the browser. We use _blank
as a value in the target
attribute in the anchor tag. Check below,
1 |
<a href="http://www.phpcoder.tech" target="_blank">Visit PHPCODER.TECH</a> |

If you want to do the with javascript to open link in a new tab, then we can use the window.open()
the method as the best option in javascript.
window.open() method take two parameters,
- URL
- _blank value
Syntax of Open URL in New Tab using JavaScript
1 |
window.open("URL", "_blank"); |
Below example is open http://www.phpcoder.tech
URL in a new tab of the browser,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<html> <body> <p>Click the button to open a new tab </p> <button onclick="NewTabJS()"> Open PHPCODER.TECH </button> <script> function NewTabJS() { window.open("http://www.phpcoder.tech", "_blank"); } </script> </body> </html> |
Also Check:
Tags: #javascript #window.open() #JavaScriptwindow.openNewTtab
Happy Coding..!
Pingback: CSS Background Image Text Effect - PHPCODER.TECH
Pingback: JavaScript Append HTML to Body - PHPCODER.TECH