javascriptjquerygoogle-chrome-extensiongoogle-calendar-apigetscript

Calling a js function from another content script file


I have a file a.js that is related to the a.html file. Then. I have another content-script file, that modifies calendar.google.com I added a button on the calendar page, and when I press it, I want to call a function from the other file: I have done this. but I get an 404 error for it:

  $.getScript("vidyoChromeExt.js", function(){

                           alert("Script loaded but not necessarily executed.");
                            reLogin("event");

                        });

The issue is that it searches for the file inside:

jquery-2.0.3.min.js:6 GET https://calendar.google.com/calendar/vidyoChromeExt.js?_=1465892174555 404 ()

so instead of taking the root from my extension, it takes the root from the calendar.google.com page, so it won't find my file. How can I make it point to the files from my project?


Solution

  • Use chrome.runtime.getURL("vidyoChromeExt.js").

    You have to include the file in the web_accessible_resources section of manifest file:

    "web_accessible_resources": ["vidyoChromeExt.js"]