Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a new tab in Javascript?

I would like to open in a new tab a page of my website.

I've tried to use the window.open function but it seems like it's not supported anymore.

Those are a few options I've tried in local :

url = "localhost:3000/my-other-page"
window.open(url, '_blank');

OR

var popup  = window.open("about:blank", "_blank");
popup.location = url;

The first option opened the page in a new tab but the screen stayed black.

What would be the best way to open this url ? Is it still supported by current browsers?

like image 511
Benjamin Avatar asked Nov 19 '25 13:11

Benjamin


1 Answers

Show your sample url, I think you have to use a full protocol url, instead of a domain name.

ex:

Use https://google.com instead of google.com

var url =  'https://google.com';
window.open(url, '_blank');
like image 169
hoangdv Avatar answered Nov 22 '25 04:11

hoangdv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!