0

(This question is actually not related to redactor at all. It could be applied to anything: JQuery, CodeMirror, etc.)

I would like to create a chrome extension to change text inside redactor-editor. If I open the console, I could type:

$("#editor").redactor("code.set", "<p>foo bar</p>")

and this will give me what I want.

Now, I write an extension to do this. However, it seems that redactor couldn't be accessed from the content script. This is not surprising, as it's documented that Chrome extensions are working in an isolated world (in fact, I think my JQuery and the site's JQuery wouldn't even be the same). However, I also know that there is a hack to do this; that is, to append a script tag which runs that command to the DOM. After doing that, however, I still get the error.

Uncaught TypeError: $(...).redactor is not a function

Do you have any idea on how I can access redactor?

Sorawee Porncharoenwase
  • 6,305
  • 1
  • 14
  • 28
  • 1
    Try adding the injected script to web_accessible_resources in the manifest, see [this answer](http://stackoverflow.com/a/20513730/3959875) – wOxxOm Aug 29 '15 at 14:02
  • Yes it works! Thx so much! – Sorawee Porncharoenwase Aug 29 '15 at 16:17
  • @wOxxOm Note that the link you provided is not completely correct. The manifest file should list the injected script, not the content script. Anyway, I got it now! :). Feel free to answer it below so that I can mark it as a correct answer. – Sorawee Porncharoenwase Aug 29 '15 at 16:24
  • possible duplicate of [Building a Chrome Extension - Inject code in a page using a Content script](http://stackoverflow.com/questions/9515704/building-a-chrome-extension-inject-code-in-a-page-using-a-content-script) – wOxxOm Aug 29 '15 at 16:29
  • Method 1 in the linked duplicate answer contains the solution for this case. – wOxxOm Aug 29 '15 at 16:31

0 Answers0