javascript - chrome tab focus index API -
i use chrome api
tabs open multiple links @ once.
but problem last link open (or focus) first.
$scope.data = [{ "url":"http://www.google.com" },{ "url":"http://www.bing.com" },{ "url":"http://www.yahoo.com" }]; angular.foreach($scope.data, function(data){ chrome.tabs.create({ url: data.url }); });
it's not suitable reserve loop because arrangement of tabs messed up. think should use https://developer.chrome.com/extensions/tabs#method-update i've no idea how it. help.
the method chrome.tabs.create
allows specify whether new tab should become active. here sample code keeps first of several opened tabs active:
for (var i=0; i<urlarray.length; i++) { chrome.tabs.create({ url: urlarray[i], active: i==0 }); }
the above written after xan's suggestion; older version chrome.tabs.update
follows.
the update
method can used change active tab:
chrome.tabs.update(id, {active: true});
makes active tab given id. demonstration, following work code:
chrome.tabs.query({url: $scope.data[0]}, function(tabsarray) { chrome.tabs.update(tabsarray[0].id, {active: true}); });
but better keep record of tab ids create them, not query them later. that, you'd need provide callback function chrome.tabs.create
command, receive parameters of created tab, including id.
Comments
Post a Comment