Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

popup window at chrome extensions' context menu

I'm developing a chrome extension and have a problem. I've added an item to chrome's context menu and want to open a popup window if the menu item is clicked. My code looks like this:

function popup(url) {
window.open(url, "window", "width=600,height=400,status=yes,scrollbars=yes,resizable=yes");
}

chrome.contextMenus.create({"title": "Tumblr", "contexts":["page","selection","link","editable","image","video","audio"], "onclick": popup('http://example.com')});

But this code doesn't work as I want. The popup window doesn't appear after an click on the context item, but rather after a refresh of the extension in the chrome extension preferences.

Thanks in advance!

like image 345
Patrick Lenz Avatar asked Jul 31 '12 14:07

Patrick Lenz


1 Answers

chrome.contextMenus.create({... "onclick": popup('http://example.com')})

invokes the popup function immediately, causing a pop-up to be opened. You have to pass a reference to a function. To get your code to work, wrap the function call in a function:

chrome.contextMenus.create({
    "title": "Tumblr",
    "contexts": ["page", "selection", "link", "editable", "image", "video", "audio"],
    "onclick": function() {
        popup('http://example.com');
    }
});

window.open() can be used to create a popup. An alternative method (just to let you know that it exists) is chrome.windows.create.

like image 97
Rob W Avatar answered Oct 02 '22 04:10

Rob W