开发者

Using a .JS file as a reference library in chrome extension?

开发者 https://www.devze.com 2023-04-11 09:22 出处:网络
I want to put all my functions in js file and refer to them from my code in the extension is th开发者_如何学编程at possible?If you wana use it from a html:

I want to put all my functions in js file and refer to them from my code in the extension is th开发者_如何学编程at possible?


If you wana use it from a html:

<script type="text/javascript" src="path/my_functions.js"></script>

If you wanna refer to them from a content script:

chrome.tabs.executeScript(null, {file: "path/my_functions.js"}, function(){
   oneOfMyFunctions();
});

If you wanna refer to them from the manifest file:

{
  "name": "My extension",
  ...
  "content_scripts": [
    {
      "matches": ["http://www.google.com/*"],
      "js": ["path/my_functions.js"]
    }
  ],
  ...
}

More info available here.

0

精彩评论

暂无评论...
验证码 换一张
取 消