How to Open URL in New Tab using JavaScript ... | js new page
InHTML,theanchortag[1]isusedtoopenURLsinanewtabinanelementaryandstraightforwardmanner.Moreaboutthistagcanbelearntfromthis[2]article.However,sometimesthere’saneedtodothesameusingJavascript.Inthiscasewindow.open()[3]methodprovestobehelpful.Thewindow.open()methodisusedtoopenanewbrowserwindoworanewtabdependingonthebrowsersettingandtheparametervalues.Approach: Toopenanewtab,wehavetouse_blankinthesecondparameterofthewindow.open()method.Thereturnvalueofwindow.open()isarefer...
In HTML, the anchor tag[1] is used to open URLs in a new tab in an elementary and straightforward manner. More about this tag can be learnt from this[2] article. However, sometimes there’s a need to do the same using Javascript. In this case window.open()[3] method proves to be helpful. The window.open() method is used to open a new browser window or a new tab depending on the browser setting and the parameter values.
Approach:
To open a new tab, we have to use _blank in the second parameter of the window.open() method.The return value of window.open() is a reference to the newly created window or tab or null if it failed.Do not add a third parameter to it as it will result in the opening of a new window rather than a tabSyntax: