Javascript open()应在同一选项卡中打开链接

Javascript open()应在同一选项卡中打开链接,javascript,html,window.open,Javascript,Html,Window.open,我对javascript非常陌生,并编写了一个程序,将查询字符串作为链接打开。 我使用了window.open(),但链接正在新选项卡中打开, 我想在同一选项卡中打开此链接。 代码如下 var strquerystring; if(fromvalue==""||tovalue==""){ alert('kindly fill all the details'); }else{ window.open(strquerystring); } 使用 而不是窗口。打开。 然后它将更改当

我对javascript非常陌生,并编写了一个程序,将查询字符串作为链接打开。
我使用了window.open(),但链接正在新选项卡中打开,
我想在同一选项卡中打开此链接。
代码如下

var strquerystring;  
if(fromvalue==""||tovalue==""){  
  alert('kindly fill all the details');
}else{
  window.open(strquerystring);
}
使用

而不是窗口。打开。 然后它将更改当前URL。

使用以下任一选项:

// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");

// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";

如果要更改当前URL,请执行以下操作:

location.replace(strquerystring);

您需要使用name属性:

window.open("www.youraddress.com","_self");

而不是要求浏览器打开一个新窗口。尝试要求浏览器打开一个新位置

所以在你的else条款中:

window.location = (window.location + strquerystring);
这将告诉浏览器导航到给定的位置。而不是打开一个新窗口。这样就可以让你在同一个“标签”


希望对您有所帮助。

您是否尝试过使用窗口位置?
window.location = (window.location + strquerystring);