我正在尝试在新选项卡中打开应用程序的URL,当用户单击同一链接时,它将集中在打开的选项卡上。这在chrome中效果很好。 IE / FF其不起作用。
<head>
<script type="text/javascript">
var childWindowTab;
function openTab() {
var pathName = '/myurl';
var tabExists = false;
if (childWindowTab) {
if (childWindowTab.location.pathname === pathName) {
if (!childWindowTab.closed) {
console.log(childWindowTab, childWindowTab.focus());
setTimeout(function() {
childWindowTab.focus();
});
tabExists = true;
}
}
}
if (!tabExists) {
childWindowTab = window.open(pathName + window.location.search, '_blank');
}
}
</script>
</head>
<body>
<a href="#" onclick="openTab()">opne tab</a>
</body>
</html>