简体   繁体   English

关闭正在运行Chrome扩展程序的弹出窗口

[英]Closing a popup window which is running a chrome extension

Summary : I am trying to close a popup window which is running a chrome extension in it . 摘要:我正在尝试关闭一个正在运行chrome扩展程序的弹出窗口。 for some reason when a chrome window runs a extension in it , window.close is not working on it. 由于某种原因,当chrome窗口在其中运行扩展名时,window.close无法在其上运行。

Explanation : 说明:

My GWT application needs to interact with a legacy system which only runs in IE 7 , as solution I am opening a popup window with url 'chrome-extension://hehijbfgiekmjfkfjpbkbammjbdenadd/iecontainer.html#url=www.legacysystem.com', which force the legacysystem to be opened with IE tab in the new window. 我的GWT应用程序需要与仅在IE 7中运行的旧系统进行交互,作为解决方案,我正在使用url'chrome-extension://hehijbfgiekmjfkfjpbkbammjbdenadd/iecontainer.html#url=www.legacysystem.com'打开一个弹出窗口强制在旧窗口中使用IE标签打开旧版系统。 The requirement it that there should be only one window open for legacy system all the time , so i need to close the opened window if a user tries to open another one. 要求始终为旧系统仅打开一个窗口的要求,因此如果用户尝试打开另一个窗口,则需要关闭打开的窗口。

here is my code for opening the new window 这是我打开新窗口的代码

 <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>

Problem when i try this code without IE tab all works fine , but when i try this with IE tab the code is not able to close the chrome window . 当我在没有IE选项卡的情况下尝试此代码时,所有问题都可以正常工作,但是当我在IE选项卡中进行尝试时,该代码无法关闭镶边窗口。

As far as i am aware chrome.* api's not applicable as I am not running this code with in extension 据我所知chrome。* api不适用,因为我没有使用in扩展名运行此代码

Any Idea's or solution is much appreciated. 任何想法或解决方案都倍受赞赏。

Not the solution you might be expecting (or wishing for), but it might work for you. 不是您可能期望(或希望)的解决方案,但它可能对您有用。

IE Tab uses a plugin (namely blackfishietab.dll ), so I do not think there is much you can do (or even dig deeper into it to find the exact problem). IE Tab使用了一个插件(即blackfishietab.dll ),因此我认为您无法做很多事情(甚至更深入地研究它来找到确切的问题)。 But (even if the exact cause of the problem is not known (to me)) I have 3 solutions to propose: 但是(即使不知道问题的确切原因(对我来说))我也可以提出3种解决方案:

Solution 1 解决方案1

If the GWT application is run from your PC only (or from specific PC you have administrative access to) you can modify the IE Tab extension source code, to enable you to close the open window. 如果仅从您的PC(或具有管理访问权限的特定PC)运行GWT应用程序,则可以修改IE Tab扩展名源代码,以使您能够关闭打开的窗口。
DISCLAIMER: I am not sure you are legaly entitled to do this, so you might want to get an express permission from the developer first. 免责声明:我不确定您是否有权这样做,因此您可能希望先获得开发人员的明确许可。

Solution 2 解决方案2

With little extra overhead (and considering you can impose that of your users), you could implement your own chrome-extension and interract with it (instead of with IE Tab extension directly). 几乎没有额外的开销(考虑到您可以强加给您的用户),您可以实现自己的chrome扩展并与它进行交互(而不是直接与IE Tab扩展一起使用)。 IE you could ask your extension to open the legacy system using IE Tab. IE,您可以要求您的扩展程序使用IE Tab打开旧版系统。 You extension could then keep track of the opened window and close it when required. 然后,您的扩展程序可以跟踪打开的窗口,并在需要时将其关闭。
(The extension will be able to close the window, because it will have access to the powerful chrome.* APIs.) (该扩展程序将能够关闭该窗口,因为它可以访问功能强大的chrome.* API。)

Solution 3 解决方案3

This solution does not provide a way for you to close the IE Tab window programmatically, but it still ensures that there will be no more than 1 IE Tab windows opened from your GWT app. 该解决方案无法为您提供以编程方式关闭IE Tab窗口的方法,但仍可以确保从GWT应用程序打开的IE Tab窗口不超过1个。
According to the docs regarding window.open(srtUrl, strWindowName) 's second parameter: 根据有关window.open(srtUrl, strWindowName)的第二个参数的文档:

If a window with the name strWindowName already exists, then strUrl is loaded into the existing window. 如果已经存在名称为strWindowName的窗口,则将strUrl加载到现有窗口中。

Thus, you don't have to worry about closing the window first, as long as you always use the same name for the IE Tab window: 因此,您不必担心首先关闭窗口,只要您始终对IE Tab窗口使用相同的name

function legacySystemWindow(name, url) {
    //WindowDialog.close(name);   // <-- You can get rid of this line
    WindowDialog.open(name, url);
}

(You, also, don't need to keep track if opened tabs, since you don't need to close them programmatically.) (同样,您也无需跟踪打开的标签页,因为您无需以编程方式将其关闭。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM