简体   繁体   English

控制popup.html何时弹出

[英]Controlling when the popup.html pops

I'm making an extension that gets the user current selection, uses it to change popup.html and shows it to the user. 我正在制作一个扩展程序,用于获取用户当前选择,使用它来更改popup.html并将其显示给用户。 I would like to be able to do a couple things: 我希望能做几件事:

  1. Before showing the fully generated page, the starting popup.html without content is shown. 在显示完全生成的页面之前,将显示没有内容的起始popup.html。 How do I avoid this? 我该如何避免这种情况?
  2. In some occasions (for instance, when there is no selection) I don't want the popup.html to show up at all. 在某些情况下(例如,没有选择时)我不希望popup.html显示出来。

Any suggestions? 有什么建议?

I think Page Action would better suit your needs as you will be able to hide popup icon completely. 我认为Page Action会更好地满足您的需求,因为您可以完全隐藏弹出图标。 Otherwise you can make popup body disappear using: 否则你可以使用弹出体消失:

chrome.browserAction.setPopup({popup: ""});

As to your first question - there are two options. 至于你的第一个问题 - 有两种选择。 If popup html remains pretty much the same all the time (like a template), only data changes - you can pass the data using GET url parameters before the popup is clicked using: 如果popup html始终保持相同(如模板),只有数据更改 - 您可以使用GET url参数传递数据,然后单击弹出窗口:

chrome.pageAction.setPopup(tabId, popup: {"popup.html?param=value&..."}); 

(in the popup you would need to parse url to get the data). (在弹出窗口中,您需要解析url以获取数据)。 If there are several different popup styles, you can use this method as well to switch between different files. 如果有多种不同的弹出样式,您也可以使用此方法在不同的文件之间切换。

In case popup html is completely different each time, you can prepare popup html in the background page when a user makes selection, and then pass ready to display html when popup opens. 如果弹出html每次完全不同,您可以在用户进行选择时在后台页面中准备弹出式html,然后准备好在弹出窗口打开时显示html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM