Firefox 中的隐藏输入元素
我在 Firefox 中使用 fckeditor 时遇到问题。 当用户转到某个页面时,html(编码)存储在隐藏的输入元素中。 我调用预定义的 fckeditor javascript 事件,用隐藏的 ContentBody 元素中的 html 填充我的编辑器。
function FCKeditor_OnComplete( editorInstance )
{
editorInstance.InsertHtml("");
var sample = document.getElementById("ContentBody").value;
editorInstance.InsertHtml(sample);
}
在 IE 中,这会自动将所需的文本填充到编辑器中,但在 Firefox 中则不会。 Firebug 给我错误:
A 为 null [在此错误上中断] var FCKW3CRange=函数(A){this._Docume...eateFromRange(this._Document,this);}};\r\n
使用 Firebug 我可以确定在使用 Firefox 时不会触发事件方法 FCKeditor_OnComplete()。 然而,它是在 IE 中。 关于如何让它在两种浏览器中工作有什么想法吗?
ContentBody 的 HTML 是:
I'm having troubles with fckeditor in Firefox. When the user goes to a page, the html (encoded) is stored in a hidden input element. I call the predefined fckeditor javascript event to populate my editor with the html from the hidden ContentBody element.
function FCKeditor_OnComplete( editorInstance )
{
editorInstance.InsertHtml("");
var sample = document.getElementById("ContentBody").value;
editorInstance.InsertHtml(sample);
}
This automatically populates the editor with the desired text in IE, but in Firefox it doesn't. Firebug gives me the error :
A is null [Break on this error] var
FCKW3CRange=function(A){this._Docume...eateFromRange(this._Document,this);}};\r\n
Using Firebug I can determine that the event method FCKeditor_OnComplete() just isn't fired when using Firefox. It is, however, in IE. Any ideas on how to get this to work in both browsers?
The HTML for ContentBody is:<input type="hidden" name="ContentBody" id="ContentBody" value="<%=Model.Article%>" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这太有趣了。 我从未使用过 FCKeditorOnComplete (我必须删除下划线才能使 WMD 满意),但它看起来是一个很好的钩子。 您是否尝试在下面的 FCKEditor 函数中放置一个断点? 您使用 Firefox 到达那里吗? 也许这与您的 FCKeditorOnComplete 的物理位置有关......
That is interesting. I never used FCKeditorOnComplete (I had to remove underscore to make WMD happy), but it looks like a good hook. Did you try to put a break point this the FCKEditor function below? Do you arrive there with Firefox? Maybe it is something to do with where your FCKeditorOnComplete is physically situated...
您确定您的标签具有属性 id="ContentBody" 吗? 可以使用属性 name="ContentBody",IE 会(技术上错误地)将其解释为 getElementById 的 ID 属性。 仅当您正确使用 id 时,Firefox 才会找到它。
Are you sure your tag has the attribute id="ContentBody"? It's possible to use the attribute name="ContentBody", and IE will (technically incorrectly) interpret that as the ID attribute for getElementById. Firefox will only find it if you use id correctly.
上个月我在开发一个新项目时找到了解决方案。 首先,我将编码的 HTML 字符串存储在隐藏的输入元素中:
该函数是 FCKeditor 实例完成加载时调用的事件。
Firefox 似乎需要 javascript 来调用parent.document.getElementById()
I came to a solution to this last month while working on a new project. First I store the encoded HTML string in a hidden input element:
This function is the event that is called when the FCKeditor instance in finished loading.
It seems Firefox requires the javascript to call parent.document.getElementById()
如果您在错误发生时中断并向上遍历堆栈,为什么 A 没有设置? 或者,中断
document.getElementById("ContentBody").value
并沿着堆栈向下查找,寻找更具体的原因。
If you break on the error and walk up the stack, why is A not set? Or, break on
document.getElementById("ContentBody").value
and walk down the stack, looking for a more specific cause.