我如何在下方的同一个标签中打开Goog​​le Chrome扩展程序弹出窗口的链接? [英] How do I have a link from a Google Chrome extension popup open in the same tab underneath?

查看:168
本文介绍了我如何在下方的同一个标签中打开Goog​​le Chrome扩展程序弹出窗口的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



目前有这个:

  //在弹出菜单中打开链接
if(document.location.search =='?popup')
$('a')。 attr('target','_blank');

但是_blanks会在新选项卡中打开。任何帮助将不胜感激 - 谢谢!

解决方案

您需要先通过
获取当前选定的选项卡 http://code.google.com/chrome/extensions/tabs.html #method-getSelected

然后你使用tab.id,回调已经触发,并用一个url更新它:
http://code.google.com/chrome/extensions/tabs.html#method - 更新



例如:

  chrome。 (),
});

如果您想让弹出页面中的每个链接更新打开的当前选项卡。您可以执行以下操作(正如您在注释中提到的,但是使用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(); //关闭弹出。
});


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!

解决方案

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.
});

这篇关于我如何在下方的同一个标签中打开Goog​​le Chrome扩展程序弹出窗口的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆