在新标签中打开Chrome扩展程序 [英] Open chrome extension in a new tab

查看:154
本文介绍了在新标签中打开Chrome扩展程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个Chrome扩展。想知道popup.html是否可以在新标签中打开?每一次点击页面,弹出消失:( ..想知道我是否可以坚持到页面或有一种方法来打开新页面中的扩展名?

解决方案

是的,弹出式页面只是一个普通的扩展页面,您可以执行以下操作以从后台页面打开新的弹出式选项卡,每当用户首先安装扩展程序,我打开about页面,您可以为弹出页面执行相同操作。

  chrome.tabs.create ({url:'popup.html'})

对于我的一个扩展我的环聊,我在弹出窗口中有一个小的打开为标签页按钮,我将点击事件绑定到该链接执行此操作:

  chrome.tabs.create({url:chrome.extension.getURL('popup.html# window')}); 

我之所以通过哈希i因为我想在用户打开弹出窗口时添加更多的内容,因为有更多的房地产可供玩耍。



在弹出窗口中,我使用普通的JavaScript区分我是在新标签页中打开标签还是在普通页面中打开标签,如下所示:

  if(window.location。 hash =='#window'){
this.displayAsTab = true;





$ b

你可以这样做,让你的分机用户体验更好。


I have implemented a chrome extension. Was wondering if the popup.html can be opened in a new tab? Every single click on the page, and the popup disappears :( .. Was wondering if I can stick it to the page or is there a way to open the extension in a new page?

解决方案

Yes, a popup page is just a normal extension page, you can do the following to open a new popup tab from the background page. I use that every time when the user first installs the extension, I open the about page, you can do the same for the popup page.

chrome.tabs.create({url: 'popup.html'}) 

For one of my extensions, My Hangouts, I have a small "open as tab" button within the popup, I bind the click event for that link to execute this:

chrome.tabs.create({url: chrome.extension.getURL('popup.html#window')});

The reason why I passed the hash is because I wanted to add more content when the user opens it in a popup because there is more real estate to play with.

Within the popup, I use normal JavaScript to differentiate whether I opened the tab in the new tab page or in a normal page like the following:

if (window.location.hash == '#window') {
  this.displayAsTab = true;
}

You can do tricks like this to make your extensions user experience better.

这篇关于在新标签中打开Chrome扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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