我的網頁上有一個按鈕。其代碼是:如何通過單擊按鈕在同一選項卡上打開新的網頁?
/* code of the other forms */
<form method="get" onsubmit="return validation()" >
<input type="submit" id="x" value="Search" onmouseover="mover(this)" onmouseout="mout(this)" />
</form>
當我點擊按鈕應該驗證其他窗體的值並在同一個選項卡上打開新的網頁。我對驗證部分沒有問題。問題是新的網頁在新標籤中打開,這不是我想要的。到目前爲止,代碼是:
function validation(){
var x=document.forms["flyrics"]["lyrics"].value;
if (x==null || x=="")
{
alert("Search without Lyrics?");
return false;
}
var y=document.forms["fartist"]["artist"].value;
if (y==null || y=="")
{
alert("Search without Artist Name?");
return false;
}
window.open("songList.html", "_self");
}
在最後一行中,它是在同一個選項卡上打開新頁面的代碼。但每次點擊按鈕時都會打開一個新選項卡。我如何糾正它? 我也試過使用下面的代碼。但我不知道爲什麼他們都沒有在同一個標簽上打開新頁面。
location.href = "songList";
window.location="songList.html";
window.open("songList.html", "currentWindow", "");
實際問題在哪裏?需要幫助解決它。 我需要使用javascript和html來做到這一點。
'window.location'不應該在新選項卡中打開,除非您的瀏覽器設置覆蓋它。 – Mooseman
確切地說,window.location不應該在新選項卡中打開,而是在我的代碼中打開。我很困惑它爲什麼會發生。我如何知道我的瀏覽器正在覆蓋它? – Giliweed
嘗試使用計算機上其他瀏覽器的相同頁面。 – Mooseman