1

I create a Chrome extension and want add an option page where a radio buttons sets a variable from variable array in background.js.

I have background.js with a code like

var xhr = new XMLHttpRequest();
var protocol = "https://";
var country = ["de","ch"];
var middle = ".sistrix.com/toolbox/__loadModule/domain/";
var d = currentDomain();
var end = ".html";

xhr.open("GET", protocol+country+middle+d+end, true);

Further i have a file options.html, containing this code

<select>
  <option value="de">Germany</option>
  <option value="ch">Swiss</option>
</select>

Now i want that selecting of an option in options.html () sets corresponding variable from an array var country = ["de","ch"]; into xhr.open("GET", protocol+country+middle+d+end, true); as country.

Scenario:

  • user clicks with the right mouse button on the extension icon
  • options page is opened,
  • user selects an option, i.e. de - Germany
  • after this and until user sets another option, background.js uses corresponding variable de from variable array var country = ["de","ch"]; in xhr.open as country.

PS: some answers about passing data from popup to background don't match my need. I want to have options explicitely under options - here https://easycaptures.com/fs/uploaded/1232/thumbs/7819701093_b.jpg, not in popup, which opens after clicking with the left mouse button on extension icon.

Evgeniy
  • 2,337
  • 2
  • 28
  • 68
  • Does this answer your question? [Call a function in background from popup](https://stackoverflow.com/questions/5443202/call-a-function-in-background-from-popup) – Titus Feb 01 '20 at 13:35
  • @Titus Not really - i want to have the option select not in `popup.js`, buit explicitely in options. As far i know `popup` opens after clicking on the extension icon with the left mouse button - i want to have it there: https://easycaptures.com/fs/uploaded/1232/thumbs/7819701093_b.jpg – Evgeniy Feb 01 '20 at 14:23
  • All solutions in all the answers to that question will work on both pop-ups and options pages. – Titus Feb 01 '20 at 15:59
  • @Titus does it mean, in Method C of https://stackoverflow.com/a/13549245/1992004 i could use instead of `popup.html` and `popup.js` `options.html` and `options.js`? – Evgeniy Feb 01 '20 at 19:11
  • Yes, that is right. – Titus Feb 02 '20 at 05:44

0 Answers0