简体   繁体   English

jQuery未在chrome扩展内容脚本中加载

[英]JQuery is not loading in chrome extension content script

I am trying to create a chrome extension that interacts with and changes the content of my University's Job Board in order to add ratings from glassdoor. 我正在尝试创建与我的大学工作委员会互动并更改其内容的chrome扩展程序,以便从glassdoor添加等级。 This is my first extension, so please forgive any obvious errors. 这是我的第一个扩展程序,因此请原谅任何明显的错误。

manifest.json: manifest.json的:

{
  "manifest_version": 2,
  "name": "My Cool Extension",
  "version": "0.1",
  "background": {
    "scripts": ["background.js"]
  },
  "content_scripts": [
    {
      "matches": [
        "https://lehigh-csm.symplicity.com/students/*",
        "https://api.glassdoor.com/api/*"
      ],
      "js": ["jquery.min.js", "content.js"]
    }
  ],
}

content.js: content.js:

var jsonFile = "https://api.glassdoor.com/api/api.htm?t.p=51863&t.k=kPRnCOceJPO&userip=0.0.0.0&useragent=&format=json&v=1&action=employers&q=test";
$.getJSON(jsonFile, function(data) {
    var items = [];
    console.log(data);
});

However I am getting the error: Uncaught ReferenceError: $ is not defined 但是我收到错误: Uncaught ReferenceError: $ is not defined

Any clue what I could be doing wrong? 有什么线索我可能做错了吗? I tried browsing some of the similar questions but cannot get their solutions to work. 我尝试浏览一些类似的问题,但无法获得他们的解决方案。

Thanks! 谢谢!

Well the answer is obvious, you haven't imported a jQuery file. 答案很明显,您尚未导入jQuery文件。 How to do this is beyond my knowledge unless you're putting it into a web page but you can download the jQuery files here: https://jquery.org/ 除非您将其放入网页,否则如何做到这一点是我所不知道的,但是您可以在此处下载jQuery文件: https : //jquery.org/

If this isn't possible to put jQuery into an extension then try changing your code to just plain JavaScript. 如果无法将jQuery扩展,请尝试将代码更改为纯JavaScript。 All jQuery does is it makes JavaScript shorter, more simple, or easier to use. jQuery所做的只是使JavaScript变得更短,更简单或更易于使用。 You can translate jQuery to JavaScript with a few quick Google searches... 您可以通过一些快速的Google搜索将jQuery转换为JavaScript ...

This MAY help. 可能会有所帮助。 I dunno. 我不知道。 http://api.jquery.com/jquery.getjson/ http://api.jquery.com/jquery.getjson/

Edit: Load JQuery into a Chrome extension? 编辑:将 JQuery加载到Chrome扩展程序中?

How to use jQuery in chrome extension? 如何在Chrome扩展程序中使用jQuery?

Google Chrome Extensions: How to include jQuery in programmatically injected content script? Google Chrome扩展程序:如何在以编程方式注入的内容脚本中包含jQuery?

Try these 试试这些

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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