iLoch
iLoch

Reputation: 769

Do Google Chrome extensions work in popup windows opened with Javascript?

So I'm working on creating an extension that'll need to work within a popup window that is triggered by my website... Standard Javascript...

function openwin(){
    window.open('http://stackoverflow.com','myname','height=100,width=100');
}

Now I need my extension to load within that window. Let's say the extension's purpose is to just alert a message, when I load that window the background.js should fire and do that, correct?

Upvotes: 0

Views: 3703

Answers (2)

iLoch
iLoch

Reputation: 769

Here's my answer after looking through the API. As I said, it checks each new window being created and checks the parameters of that window. Here's the code, which can be added to the background.js file of your extension:

chrome.windows.onCreated.addListener(function(win){
    chrome.windows.get(win.id,{populate:true},function(tabwin){
        setTimeout(function(){
            chrome.tabs.executeScript(tabwin.tabs[0].id,{code:"alert(JSON.stringify(window));",runAt:'document_idle'});
        },500);
    });
});

Upvotes: 0

Larry Battle
Larry Battle

Reputation: 9178

chrome.windows.create(object createData, function callback)

Creates (opens) a new browser with any optional sizing, position or default URL provided.

From: http://code.google.com/chrome/extensions/windows.html#method-create

Try this example:

var props = {
    url: "http://www.stackoverflow.com",
    height: "100",
    width: "100",
    type: "popup"
}

chrome.windows.create(props, function(windowObj){
    console.log("Here's the window object.");
    console.dir(windowObj);
});

Upvotes: 2

Related Questions