Control when popup.html appears

I am making an extension that receives the user's current selection, uses it to modify popup.html, and shows it to the user. I would like to be able to do a couple of things:

  • Before showing the fully generated page, the initial popup.html without content is displayed. How to avoid this?
  • In some cases (for example, when there is no choice), I do not want popup.html to be displayed at all.

Any suggestions?

+4
source share
1 answer

I think the Page Action will be better suited to your needs as you can completely hide the popup. Otherwise, you can disable the popup using:

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

As for your first question, there are two options. If the popup html remains almost the same all the time (for example, a template), only the data changes - you can transfer the data using the parameters of the GET URL before clicking on the click, using:

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

(in the pop-up window you will need to parse the URL to receive the data). If there are several different popup styles, you can also use this method to switch between different files.

In the case where the popup html is completely different each time, you can prepare the popup html on the background screen when the user makes a choice, and then transfer the html ready for display when the popup opens.

+4
source

All Articles