当我的扩展程序可以访问 Firefox 中当前显示的网页的 INPUT
(输入 "text"
)或 TEXTAREA
元素时,我可以使用 < code>QueryInterface 将其转换为 nsIDOMNSEditableElement
类型的 JS 对象,然后我可以使用 .editor
访问关联的 nsIEditor
。
但是,Firefox 也支持其他可编辑元素,例如,如果任何元素(及其子元素)将 contentEditable
属性设置为 true
,则该元素(及其子元素)都是可编辑的。此外,如果将 designMode
设置为 on
,则整个文档都可以编辑。无论哪种情况,可编辑元素都不是 nsIDOMNSEditableElement 的实例; nsIDOMNSEditableElement
的 QueryInterface
失败。
由于这些可编辑元素也可以启用拼写检查(如果它们的属性 spellcheck
设置为 true
),我假设有一个实例 nsIEditor
> 与他们相关。
我如何获得它的参考?
When my extension gets access to an INPUT
(type "text"
) or TEXTAREA
element of the currently displayed webpage in Firefox, I can use QueryInterface
to cast it to a JS object of type nsIDOMNSEditableElement
and then I can access the associated nsIEditor
using .editor
.
However, Firefox supports other elements to be editable as well, e.g. any element (and its children) is editable if it has the attribute contentEditable
set to true
. Further a whole document can be editable if it has designMode
set to on
. In either case, the editable elements are not instances of nsIDOMNSEditableElement
; QueryInterface
for nsIDOMNSEditableElement
fails.
Since those editable elements can also have spell checking enabled (if they have the attribute spellcheck
set to true
), I assume that there is an instance nsIEditor
associated with them.
How would I get a reference to it?
发布评论
评论(1)
对于可编辑框架(通过
designMode
属性),您可以像这样检索它:至于
contentEditable
- 您似乎不走运。我找不到从 JavaScript 访问编辑器的方法:nsGenericHTMLElement
类有一个GetEditor
方法,但只能通过nsIDOMNSEditableElement
接口访问只有很少的元素实现。nsIAccessibleEditableText
接口 有一个linkedEditor
属性,但由于某种原因它被标记为[noscript]
。contentEditable
是 Gecko 中相对较新的功能,看起来有人忘记让编辑器可用于 JavaScript - 可能值得在 https://bugzilla.mozilla.org/。For editable frames (via
designMode
property) you can retrieve it like this:As to
contentEditable
- you seem to be out of luck. I couldn't find a way to access the editor from JavaScript:nsGenericHTMLElement
class has aGetEditor
method but it is only accessible throughnsIDOMNSEditableElement
interface that only few elements implement.nsIAccessibleEditableText
interface has anassociatedEditor
property but it is marked as[noscript]
for some reason.contentEditable
is a relatively new feature in Gecko and it looks like somebody forgot to make the editor accessible for JavaScript - probably worth filing a bug at https://bugzilla.mozilla.org/.