Ask Your Question
1

How can jQuery be added to programmatically injected content scripts in Google Chrome Extensions?

asked 2023-06-28 17:00:56 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-28 17:21:02 +0000

pufferfish gravatar image

jQuery can be added to programmatically injected content scripts in Google Chrome extensions by following these steps:

  1. Download the jQuery library from the jQuery website.
  2. In your extension's manifest file, specify the path to the jQuery library in the "webaccessibleresources" key:
"web_accessible_resources": [
  "jquery.js"
]
  1. In your content script, create a new script element and set its "src" attribute to the path to the jQuery library:
var jqueryScript = document.createElement('script');
jqueryScript.src = chrome.extension.getURL('jquery.js');
document.head.appendChild(jqueryScript);
  1. Use jQuery in the content script as you would normally:
$(document).ready(function() {
  // Do something with jQuery
});
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-28 17:00:56 +0000

Seen: 8 times

Last updated: Jun 28 '23