简体   繁体   English

document.execCommand在firefox addon-sdk中导致错误

[英]document.execCommand causes error in firefox addon-sdk

I'm developing a Firefox extension using Firefox addon-sdk. 我正在使用Firefox addon-sdk开发Firefox扩展。 One of my content scripts is trying to insert some text into an editable div by using this standard javascript function: 我的内容脚本之一正在尝试使用此标准javascript函数将一些文本插入可编辑的div中:

document.execCommand("InsertHTML", false, 'test text');

The above code works perfectly in my Chrome extension but fails in Firefox with this error: 上面的代码可在我的Chrome扩展程序中完美运行,但在Firefox中失败,并出现以下错误:

[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLDocument.execCommand]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" data: no] [异常...“组件返回失败代码:0x80004005(NS_ERROR_FAILURE)[nsIDOMHTMLDocument.execCommand]” nsresult:“ 0x80004005(NS_ERROR_FAILURE)”数据:否]

Is there any other solution to insert text at the current position into an editable div(in a content script). 是否有其他解决方案可将当前位置的文本插入可编辑的div(在内容脚本中)。

Thanks in advance 提前致谢

In my first glance, the function doesn't exist, resp. 乍一看,该功能不存在,分别。 is not accessible: 不可访问:

Either due to NOT making the WHOLE doc editable (at least FF 3.5.13 shows that behaveiour) resp. 或由于无法使整个文档可编辑(至少FF 3.5.13表明其行为)而引起。 'midas' not invoked OR a timing problem: the invoke of midas may take some (100?) millisec. 未调用“ midas”或时序问题:调用midas可能要花费一些(100?)毫秒。 In the case editability is triggerd by script or otherwise after load of page, one should await the 'appearence' of the function (of the DOCUMENT).execCommand as midas load-completion succeeds. 如果可编辑性是由脚本触发的,或者在页面加载后触发,则应等待函数(文档)的“出现”,直到加载完成成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM