0

I`m writting an extension in which i want to open a messege in new tab (not default tab, but in tab written in HTML like in this tutorial http://xulforum.org/fosdem2012/presentation/template.html )

My problem is, that i want to pass an argument to newly opened tab, but i didn`t manage to find anything about passing an arguments on the Internet.

Can somebody help me with that please?

1 Answers1

0

You should pass your arguments in the URL of the tab you're opening, that's definitely the easiest way.

openTab("chromeTab", { chromePage: "chrome://yourext/content/foo.html?foo=bar" });

Here's a routine you can use to easily map the current URI's parameters to a javascript dictionary:

/**
 * Takes the <b>entire</b> query string and returns an object whose keys are the
 * parameter names and values are corresponding values.
 * @param aStr The entire query string
 * @return An object that holds the decoded data
 */
function decodeUrlParameters(aStr) {
  let params = {};
  let i = aStr.indexOf("?");
  if (i >= 0) {
    let query = aStr.substring(i+1, aStr.length);
    let keyVals = query.split("&");
    for each (let [, keyVal] in Iterator(keyVals)) {
      let [key, val] = keyVal.split("=");
      val = decodeURIComponent(val);
      params[key] = val;
    }
  }
  return params;
}

(warning: this is mozilla-specific javascript)

Jonathan Protzenko
  • 1,709
  • 8
  • 13
  • Thank you very much Jonathan. I have already tried something similiar, but I was using "&" instead of "?" and clearly Thunderbird had problem with it. – user1476961 Jan 16 '13 at 17:19