In this tutorial, learn how to open button link in new tab using jQuery. The short answer is: use jQuery window.open function with link first argument and
_blank as the second argument.
You can open the internal link in the same window. However, somewhere you may require to open the internal link in the new tab. Again it’s the best practice for any blogger to open the external link in the new tab.
But, how you can create a button with a link and open the link in the new tab of the browser. To get the answer to this question, keep reading this post. You may also like to read how to create an anchor link button using Bootstrap.
How to Open Button Link in New Tab Using jQuery
To open button link in new tab, you have to use the onclick attribute with the button. Add the jQuery
window.open() in the onclick attribute of the button. The onclick attribute works when someone clicks on the button.
Now, You have to add two arguments in the jQuery
The first argument of the function requires to add URL and the second takes
_blank. See the example below to create your own anchor link button.
<button type="button" onclick="window.open('https://tutorialdeep.com/sql/', '_blank');">Visit SQL Tutorial</button>
The above example contains the button with the URL in the onclick attribute of HTML. Click the above button that takes you to the new tab with link opened.
You may also like to read
Hope, you like this tutorial of how to open link in new tab using jQuery. If you have any query regarding the tutorial, please comment below.
- Open a given URL in a new tab by clicking a button
Open New Tab On Button Click
- How to Make Links Open in a New Window or Tab
Also tell me, which method you are using to open the link in new tab with jQuery.