Depends on what you want to do. You cant bass 0 or 1 as tab ID, you
must get them from chrome.tabs.getAllInWindow,
chrome.tabs.getSelected, or a callback on tabs events.
Here are two snipptes used in my extension:
------------
chrome.tabs.getAllInWindow(
undefined,
function(tabs) {
for (var i = 0, tab; tab = tabs[i]; i++) {
if (tab.url && isUrl(tab.url, getUrl())) {
chrome.tabs.update(
tab.id, {url: tab.url, selected: true});
return;
}
}
chrome.tabs.create({url: getUrl()});
}
);
It's a function that needs to open an URL defined by getUrl(), but
first looks if it's open already in a tab and reuses the tab if it's
true.
------------------
chrome.tabs.onUpdated.addListener(OnLoginHandler);
function OnLoginHandler (tabId, changeInfo, tab){ // Forces update on
login
if (changeInfo.url && changeInfo.url == loggedInURL){
// ..some code..
}
}
This one checks if any updated tab changed URL to login confirmation
page, and does some work immediately after that.
------------------
Hope it helps.
On May 20, 8:20 am, rc <
robertcare...@gmail.com> wrote:
> Hello-
>
> I've added "permissions": [ "tabs"] to the manifest.json file.
>
> In my code I've attempted to have the following activate in javascript
> when a link is click and neither work.
> chrome.tabs.update(0, {url: '
http://www.google.com'});
> chrome.tabs.update(1, {url: '
http://www.google.com'});
>
> Does anyone have a working example of chrome.tabs.update they can
> share?
>
> Thanks,
> Rob
>
> --
> You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
> To post to this group, send email to
chromium-extensi...@chromium.org.
> To unsubscribe from this group, send email to
chromium-extensions+unsubscr...@chromium.org.