use javascript to open a link in a new tab or window

im not sure why you would use this rather than using the html target="_blank" but it could be useful if you needed to open a new tab in a javascript function.

HTML

<button onclick="open_new_tab('https://kruxor.com');" class='btn btn-primary'>Open New Tab</button>

Javascript

function open_new_tab(url) {
	window.open(url, "_blank");
}

Other Items in javascript
Page Views

This page has been viewed 54 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹

Random Quote
For a long time it had seemed to me that life was about to begin - real life. But there was always some obstacle in the way, something to be gotten through first, some unfinished business, time still to be served, or a debt to be paid. Then life would begin. At last it dawned on me that these obstacles were my life.
Alfred D. Souza