views:

98

answers:

1

I want the link to appear in the tab beneath resulting in the popup going away.

Currently have this:

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

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

+1  A: 

Hi jprim,

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

Then you use the tab.id, that the callback has fired, and updating it with a url: http://code.google.com/chrome/extensions/tabs.html#method-update

For example:

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

If you want to let every link in the popup page to update the current tab opened. You can do the following (as you mentioned within the comments but with 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.
});
Mohamed Mansour
Thank you for your help! Instead of a specific URL like you provided, how do I do it for all links on the popup like I had in the example?
jprim
Something like this isn't working for me: //Opens all links from popup in same tab underneath if (document.location.search == '?popup') $('a').live('click', function(e) { var href = e.targetElement.href; chrome.tabs.getSelected({}, function(tab) { chrome.tabs.update(tab.id, {url: href}); }); });
jprim
Any help would be greatly appreciated. Thanks!
jprim
I also have permissions tab set in the manifest file.
jprim
Are there any errors in the Inspector, when you right click on the popup and choose inspect?
Mohamed Mansour
There is not. Although I cannot right click on the popup, I have to see it in the full screen version.
jprim
We will take this privately, and once we have a conclusion, we will share it back to StackedOverflow :)
Mohamed Mansour
Thanks Mohamed, I just sent you an email!
jprim
No problem! I updated the answer above in case other people will find it useful.
Mohamed Mansour