简体   繁体   中英

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?

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"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM