以下はターゲットを に設定します_blank
:
if (key == "smk") {
window.location = "http://www.smkproduction.eu5.org";
target = "_blank";
done = 1;
}
しかし、これは機能しないようです。リンクを新しいタブで起動するにはどうすればよいですか?
これが私のコードです:
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>
ベストアンサー1
window.location
現在のウィンドウの URL を設定します。新しいウィンドウを開くには、 を使用する必要がありますwindow.open
。これは動作するはずです:
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!");
}
}