I'm making an extension for Pandora and when the user clicks the extension icon (In the top right), the extension opens a new tab with pandora
. What i'm trying to avoid is the user pressing the button multiple times and opening multiple tabs that will all play music at once.
This is what I have so far:
// When extension is clicked
chrome.browserAction.onClicked.addListener(function(tab) {
// checks to see if pandora tab is already open. if it's already open,
// the script returns (Or atleast thats what I want it to do)
chrome.tabs.query({url: "/*"}, function(results) {
return;
});
// injects the javascript
chrome.tabs.executeScript(null,{file: "buy.js"});
});
I use google's Developer Site as a reference in making this and my manifest
page does have tab
permissions.
I'm making an extension for Pandora and when the user clicks the extension icon (In the top right), the extension opens a new tab with pandora.
. What i'm trying to avoid is the user pressing the button multiple times and opening multiple tabs that will all play music at once.
This is what I have so far:
// When extension is clicked
chrome.browserAction.onClicked.addListener(function(tab) {
// checks to see if pandora tab is already open. if it's already open,
// the script returns (Or atleast thats what I want it to do)
chrome.tabs.query({url: "http://www.pandora./*"}, function(results) {
return;
});
// injects the javascript
chrome.tabs.executeScript(null,{file: "buy.js"});
});
I use google's Developer Site as a reference in making this and my manifest
page does have tab
permissions.
1 Answer
Reset to default 3You'll need at least host permission for http://www.pandora.
in order to query tabs visiting it. Then you want something like:
chrome.tabs.query({url: "http://www.pandora./*"}, function(results) {
if (results.length == 0) {
chrome.tabs.create({url: 'http://www.pandora./'}, function(tab) {
chrome.tabs.executeScript(tab.id,{file: "buy.js"});
});
}
});
in order to create the tab after learning whether there's an existing tab, and then to inject the script after the new tab's created.
You'll do something similar to inject script when there is an existing Pandora tab.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745113921a4612012.html
评论列表(0条)