extviews = chrome.extension.getViews({"type": "tab"})
function focusTab(tab) {
// Focus the given tab
chrome.tabs.update(tab.id, {"selected": true});
}
for (var i=0; i++; i<=extviews.length) {
if (i == extviews.length) {
// Create new tab if past end of list and none open
chrome.tabs.create(
chrome.extension.getURL('/path/to/options.html')
);
} else if (extviews[i].location.href ==
chrome.extension.getURL('/path/to/options.html')) {
// Get the tab's object and focus the tab
extviews[i].chrome.tabs.getCurrent(focusTab);
break;
}
}
If you know options.html is the only page you'll ever have open in a
tab, you can skip the for loop and just check to see if there is at
least one item in the list.
Hi Paulo
I'm been wondering the same thing.
Currently I'm doing this:
function openOptions()
{
var id = chrome.i18n.getMessage("@@extension_id") + "/options.html";
chrome.tabs.getAllInWindow( undefined, function(tabs)
{
for( var i = 0, tab; tab = tabs[ i ]; i++)
{
if( tab.url && tab.url.indexOf( id ) != -1 )
{
chrome.tabs.update( tab.id, {selected: true} );
return;
}
}
chrome.tabs.create( {'url': chrome.extension.getURL( 'options.html' ) },
function( tab )
{
}
);
});
}
which seems to work, but it feels like it should be easier...
Maybe somebody can put me right 8-)
Cheers,
Nige
PS It's my first post - please be gentle!
Even better:var options_url = chrome.extension.getURL('options.html');chrome.tabs.query({url: options,}, function(results) {if (results.length)chrome.tabs.update(results[0].id, {active:true});elsechrome.tabs.create({url:options});})
I think Google should minify our JavaScript after reviewing and then publish...
--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/4b4a357b-c394-4254-a3ef-8d40eec7a174%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.