Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can you open a new page using javascript

i have code that sets

window.location.href = [someurl]

but i want to have it open up in a new tab. Is there anyway to have the above code include

target="_blank"

from javascript?

like image 621
leora Avatar asked Jun 28 '26 08:06

leora


2 Answers

Yes

window.open([someurl], "_blank");

or since _blank is the default

window.open([someurl]);
like image 118
Jim Blackler Avatar answered Jun 30 '26 20:06

Jim Blackler


Use window.open()

https://developer.mozilla.org/en/DOM/window.open

window.location.href just changes the location of the current window.

like image 42
JohnP Avatar answered Jun 30 '26 22:06

JohnP



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!