我试图在一个新的选项卡中打开我的应用程序的url,当用户单击同一个链接时,它将集中在open选项卡上。这在铬上很好用。它坏了。IE需要其他代码吗?
<html>
<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>