如何以编程方式访问firefox 52中内容脚本中的窗口(全局)对象?

时间:2018-06-09 12:07:36

标签: javascript firefox-addon

如何以编程方式访问firefox 52中内容脚本中的窗口(全局)对象?

window["myGlobalObjectName"]在此内容脚本案例中不起作用。

在这种情况下,似乎所有user-defined-object-name都不是window的一员。

的manifest.json:

{
  "description": "word_extension",
  "manifest_version": 2,
  "name": "word_extension",
  "version": "1.0",

  "applications": {
    "gecko": {
      "id": "word_extension@myself.myself",
      "strict_min_version": "50.0"
    }
  },
   "permissions": ["<all_urls>","tabs","nativeMessaging"],
  "content_scripts":[{
"matches":["<all_urls>"]
      ,"run_at":"document_idle","js":["content_script.js"]}]
}

content_script.js:

var test=123
function f()
{
    console.log("hello")
}

//All of the following is undefined
console.log(window.f)
console.log(window.test)
console.log(window["f"])
console.log(window["test"])

0 个答案:

没有答案