How to add target="_blank" to JavaScript window.location?
window.location
sets the URL of your current window. To open a new window, you need to use window.open
. This should work:
function ToKey(){
var key = document.tokey.key.value.toLowerCase();
if (key == "smk") {
window.open('http://www.smkproduction.eu5.org', '_blank');
} else {
alert("Kodi nuk është valid!");
}
}
Just use in your if (key=="smk")
if (key=="smk") { window.open('http://www.smkproduction.eu5.org','_blank'); }
I have created a function that allows me to obtain this feature:
function redirect_blank(url) {
var a = document.createElement('a');
a.target="_blank";
a.href=url;
a.click();
}
if you want to open a link in new tab window.open
has a problem,
my firefox detect a popup link by using window.open
' and this is not good
I was handle this by using the latest comment
var anchor = document.createElement('a');
anchor.href = 'https://example.com';
anchor.target="_blank";
anchor.click();