Text gets set in Google Groups, post-message body

2019-07-15 23:59发布

My extension, in a content script, writes to the subject and message body of the Google Groups "New Topic" page.

The updated subject is displayed just fine; it's of input type "text", so everything is easy. The body, however, is a div representing a TextBox, and when I write to it, the update doesn't appear:

(Click for a larger image.)
Screenshot of relevant HTML


I tried setting the focus to the field first, but that had no effect.

1条回答
男人必须洒脱
2楼-- · 2019-07-16 00:43

How are you trying to set the text? Show your code!

A typical way to initially set a contenteditable element is like so:

var messageBody         = document.getElementById ("p-b-0");
messageBody.innerHTML   = '<p>Line 1.</p><p>Line 2.</p>';

Note that using innerHTML erases anything that might have been on the textbox before -- which is okay for this question's scenario.

(For more advanced changes/edits, load jQuery and use it to add/delete/replace nodes inside the edit box. But, that is a subject for a different search and/or question.)

查看更多
登录 后发表回答