在同一窗口和标签页中打开链接

548

我想在同一窗口和同一标签页中打开包含链接的页面。

当我尝试使用window.open打开链接时,它会在新标签页中打开,而不是在同一窗口的同一标签页中打开。


你可能想查看这个帖子,以了解下面提出的方法之间的区别,比如“_self”和“_top”看起来很相似。 - My Work
15个回答

2

就像这样:window.open("www.youraddress.com","_self")


该代码会在当前窗口打开指定网址。

2

使用 HTML5,您可以使用历史记录 API

history.pushState({
  prevUrl: window.location.href

}, 'Next page', 'http://localhost/x/next_page');
history.go();

然后在下一页中,您可以像这样访问状态对象。
let url = history.state.prevUrl;
if (url) {
  console.log('user come from: '+ url)
}

1
这很简单。打开第一个窗口使用 window.open(url, <tabNmae>)
例如:window.open("abc.com",'myTab') 对于接下来的所有 window.open,使用相同的选项卡名称代替_self_parent等。

0

你可以做

window.close();
window.open("index.html");

它在我的网站上成功运行。


0
   Just Try in button.

   <button onclick="location.reload();location.href='url_name'" 
   id="myButton" class="btn request-callback" >Explore More</button>

   Using href 

  <a href="#" class="know_how" onclick="location.reload();location.href='url_name'">Know More</a> 

1
在当前页面重新加载并在下一条语句中通过加载新页面来取消它,这毫无意义。 - Quentin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接