Dymond
Dymond

Reputation: 2277

close pop-up with javascript

Im having a little trouble with a simple chrome extension that close a specific pop-up by its link.

When the pop-up window is popping up the main page is getting disable, and as soon as the pop-up is close, the page is enable again.

The problem I'm struggling with is that when I run my extension, the pop-up is more like being removed instead of being closed. so the pop-up window is disappearing, but the main page keeps on being disable.

BUT, if I run the javascript in the chrome dev-console the pop-up is closing correctly and the main page gets enable right away.

is this a bug? or are they other ways to close a window instead of window.close()

this is the simple javascript I'm using

(function(){
        var x = document.URL;

        var url = "www.xxxx.com/customurl";

            if(x==url){
                    window.close();
            }

    })();

Manifest

{
    "name": "ReportCloser",
    "version": "0.1",
    "permissions": [
    "tabs","<all_urls>"
    ],
    "browser_action": {
        "default_icon": "icon.png"
    },

    "content_scripts": [
        {
        "matches": [
            "http://*/*",
            "https://*/*"
            ],
        "run_at": "document_end" ,
        "js": ["script.js"]     
        }
    ], 
    "manifest_version":2
}

Upvotes: 1

Views: 974

Answers (1)

Dymond
Dymond

Reputation: 2277

So this was my problem.

The pop-up window got closed to fast, before the content was loaded. fixed that problem with an timeout.

setTimeout("window.close()",500);

Works like a charm now :)

Upvotes: 1

Related Questions