摘要:我正在尝试关闭一个正在其中运行 chrome 扩展的弹出窗口。出于某种原因,当 chrome 窗口在其中运行扩展程序时,window.close 无法处理它。
解释 :
我的 GWT 应用程序需要与仅在 IE 7 中运行的旧系统交互,作为解决方案,我正在打开一个带有 url 'chrome-extension://hehijbfgiekmjfkfjpbkbammjbdenadd/iecontainer.html#url=www.legacysystem.com' 的弹出窗口,其中强制使用新窗口中的 IE 选项卡打开旧系统。要求始终只为遗留系统打开一个窗口,因此如果用户尝试打开另一个窗口,我需要关闭打开的窗口。
这是我打开新窗口的代码
<head>
<script>
var WindowDialog = new function() {
this.openedWindows = {};
this.open = function(instanceName, url) {
var handle = window.open(url, instanceName, 'height=500,width=500');
this.openedWindows[instanceName] = handle;
return handle;
};
this.close = function(instanceName) {
if (this.openedWindows[instanceName])
this.openedWindows[instanceName].close();
};
};
function legacySystemWindow(name,url) {
WindowDialog.close(name);
WindowDialog.open(name, url);
}
</script>
</head>
<body>
<input value="Simple popup " type="button" id="1" onclick="legacySystemWindow('gmail','http://gmail.com')" />
<input value="IE Tab popup" type="button" id="2" onclick="legacySystemWindow('IETAB','chrome-extension://hehijbfgiekmjfkfjpbkbammjbdenadd/iecontainer.html#url=www.gmail.com')" />
</body>
当我在没有 IE 选项卡的情况下尝试此代码时出现问题,但当我使用 IE 选项卡尝试此代码时,代码无法关闭 chrome 窗口。
据我所知 chrome.* api 不适用,因为我没有在扩展中运行此代码
非常感谢任何想法或解决方案。