我不确定此行为是否有适当的术语。
用户故事(有2个选项卡):
1.用户单击Tab1
上的第一个链接,一个新选项卡(Tab2
)打开
2.用户单击Tab1
上的第二个链接,Tab2
刷新以反映用户在Tab1
上单击的第二个链接。
如何实现这种情况?
您可以使用句柄中的新选项卡中的第一个链接:
var tab = window.open('http://yoursite.com/action', '_blank');
然后,当用户单击第二个链接时,只需更改打开的窗口的位置:
tab.location.href = 'http://yoursite.com/second-action';
只是添加到 @hafiz的答案
您可以使用window.open()
调用。
例如:
/* The code I am writing is extremely stupid and should never be used professionally, it's just here to convey the point */
/* you html element. */
<a href="#" onlick="openLink('google.com','tab2', true)">1st Link</a>
<a href="#" onlick="openLink('google.de','tab2', false)">2nd Link</a>
/* openLink */
function openLink(url, tabName, focus) {
var tab = window.open(url, tabName);
if(focus)
/* additionally if you want to focus on the tab, this might not work on some platform. Safari(may be on iOS) I think. */
tab.focus();
}
您可以在Open()和Focus()上阅读。