简体   繁体   中英

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 . for some reason when a chrome window runs a extension in it , window.close is not working on it.

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

As far as i am aware chrome.* api's not applicable as I am not running this code with in extension

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). But (even if the exact cause of the problem is not known (to me)) I have 3 solutions to propose:

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

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). IE you could ask your extension to open the legacy system using 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.)

Solution 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.
According to the docs regarding window.open(srtUrl, strWindowName) 's second parameter:

If a window with the name strWindowName already exists, then strUrl is loaded into the existing window.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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