I've run into this problem as well. The solution I ended up using was
pretty simple. Instead of inserting HTML, create the element through
the DOM and set its handler attributes. That way you can call back
into your own content script without a problem.

Regards,
Max

On Dec 14, 4:13 pm, Alex Bennee <a...@bennee.com> wrote:
> Hi,
>
> So I'm looking at options for to do something like It's All Text in
> Chromium. One of those things was
> identifying each textarea element on the page and adding a button. I
> used the jQuery sledgehammer
> mainly out of familiarity.
>
> So this is my content script which behaves as expected:
>
> var editImgURL = chrome.extension.getURL("gumdrop.png");
> var editImgTag = "<img src=\""+editImgURL+"\">";
>
> /*
>  updateTextArea
>
>  Called when we want to update the text area with our updated text
> */
> function updateTextArea(edit_id) {
>     console.log("updateTextArea");
>
> }
>
> function findTextAreas() {
>
>     console.log("Finding text area");
>
>     text_id=0;
>
>     // Try the jQuery way
>     $('textarea').each ( function() {
>         console.log("each="+$(this));
>         id_string="eta_"+text_id;
>         $(this).attr({ emacs_chrome_id: id_string });
>         $(this).after('<a
> href="javascript:editTextArea(\''+id_string+'\')">'+editImgTag+'</a>');
>         text_id++;
>     } )
>
> }
>
> findTextAreas();
>
> Each textarea get's its attributes modified to uniquely identify the
> text area and a little clickable button added next
> to the text. However of course the anchor reference is in the page
> context and not the content script context so it
> can't call any functions in the content script.
>
> What's the best approach here? Can the page context call any part of
> the extension?
>
> Once all the text editing has been done that plan was to pass the
> updated text back to the content script which could
> go through the DOM and find the right element and tweak it.
>
> Apologies if I've missed something obvious, I'm fairly new to
> Javascirpt and extension hacking in general.
>
> --
> Alex, homepagehttp://www.bennee.com/~alex/

--

You received this message because you are subscribed to the Google Groups 
"Chromium-extensions" group.
To post to this group, send email to chromium-extensi...@googlegroups.com.
To unsubscribe from this group, send email to 
chromium-extensions+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/chromium-extensions?hl=en.


Reply via email to