How did the link appear from the Google Chrome extension popup on the same tab below?

I want the link to appear on the tab below, as a result of which the popup goes away.

Currently it is:

//Open links in tab from popup
if (document.location.search == '?popup')
$('a').attr('target', '_blank');

But _blanks opens in a new tab. Any help would be greatly appreciated - thanks!

+5
source share
1 answer

You will need to first get the currently selected tab, http://code.google.com/chrome/extensions/tabs.html#method-getSelected

Then you use tab.id, which called the callback and updated it using the URL: http://code.google.com/chrome/extensions/tabs.html#method-update

:

chrome.tabs.getSelected({}, function(tab) {
  chrome.tabs.update(tab.id, {url: 'http://google.com'});
});

, . ( , currentTarget):

$('a').live('click', function(e) {
  var href = e.currentTarget.href;
  chrome.tabs.getSelected(null,function(tab) {
    chrome.tabs.update(tab.id, {url: href});
  });
  window.close(); // To close the popup.
});
+7

All Articles