Tiago
Tiago

Reputation: 3151

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. 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. 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.

Any suggestions?

Upvotes: 4

Views: 1280

Answers (1)

serg
serg

Reputation: 111315

I think Page Action would better suit your needs as you will be able to hide popup icon completely. 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:

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

(in the popup you would need to parse url to get the data). 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.

Upvotes: 4

Related Questions