Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

javascript - 如何将target =“_ blank”添加到JavaScript window.location?(How to add target=“_blank” to JavaScript window.location?)

The following sets the target to _blank :

(以下将目标设置为_blank :)

if (key == "smk") {
    window.location = "http://www.smkproduction.eu5.org";
    target = "_blank";
    done = 1;
}

But this doesn't seem to work.

(但这似乎不起作用。)

How do I launch the link in a new tab?

(如何在新标签中启动链接?)

Here is my code:

(这是我的代码:)

 function ToKey() { var done = 0; var key = document.tokey.key.value; key = key.toLowerCase(); if (key == "smk") { window.location = "http://www.smkproduction.eu5.org"; target = "_blank" done = 1; } if (done == 0) { alert("Kodi nuk ?sht? valid!"); } } 
 <form name="tokey"> <table> <tr> <td>Type the key</td> <td> <input type="text" name="key"> </td> <td> </td> <td> <input type="button" value="Go" onClick="ToKey()"> </td> </table> </form> 

  ask by Flamur Beqiraj translate from so


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

window.location sets the URL of your current window.

(window.location设置当前窗口的URL。)

To open a new window, you need to use window.open .

(要打开一个新窗口,您需要使用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!");
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...