FCKeditor JavaScript API抛出“安全错误”;代码:“1000”;当我尝试SetHTML()

FCKeditor JavaScript API throws "Security error" code: "1000" when I attempt SetHTML()

本文关键字:SetHTML 1000 错误 安全 API 安全错误 JavaScript 代码 FCKeditor 抛出      更新时间:2023-09-26

打开一个只有一个FCKeditor窗口的网页后,我得到实例:

i = FCKeditorAPI.GetInstance( "txtText" )

这工作。我也允许:

i.GetHTML() #=> <div class=".... etc., correct output

但当尝试

i.SetHTML( "<h1>Quux</h1>" )

:

[Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_... etc. ]

我有一种不确定的感觉,在过去,我能够用SetHTML()改变FCKeditor窗口内容,但我不完全确定。该怎么办?

回复评论,我的HTML是

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250" />
<meta http-equiv="Content-language" content="cs" />
<meta http-equiv="expires" content="-1" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="private" />
<title>Foo | Bar | WebMaker | FOO.CZ</title>
<style type="text/css" media="screen">/*<![CDATA[*/@import url(http://webmaker.ooo.cz/_design/style.css);/*]]>*/</style>
<script type="text/javascript" src="http://webmaker.ooo.cz/common.js"></script>
</head>
<body>
<div id="header">
        <span><a href="http://webmaker.ooo.cz/logout.aspx">Logout</strong></span>
</div>
    <div id="main">
        <div id="content">
            <div id="tabmenu">
            </div><!-- /tabmenu -->
            <dif id="tabcontent">
              <form name="_ctl2" method="post" action="detail.aspx?article=14599" id="_ctl2">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"     value="/wEPDwULLTE2MTEzz0iZG9.....reallllly..looong...strin......6qKb5or30J5DCLKTCaFR/xc8TPHb9A=" />
<script type="text/javascript">
  <!--
      var theForm = document.forms['_ctl2'];
      if (!theForm) {
          theForm = document._ctl2;
      }
      function __doPostBack(eventTarget, eventArgument) {
          if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
              theForm.__EVENTTARGET.value = eventTarget;
              theForm.__EVENTARGUMENT.value = eventArgument;
              theForm.submit();
          }
      }
   // -->
</script>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWEQ...vsyXR4=" />
    <div class="data">
    <fieldset>
<legend>Text článku</legend>
<div><input type="hidden" id="txtText" name="txtText" value="FCK editor window contents here." /><input type="hidden" id="txtText___Config" value="HtmlEncodeOutput=true" /><iframe id="txtText___Frame" src="http://webmaker.ooo.cz/_wysiwyg/editor/fckeditor.html?InstanceName=txtText&amp;Toolbar=WebMaker" width="100%" height="400px" frameborder="no" scrolling="no"></iframe></div>  
<input type="button" onclick="GetWordsCount('txtText___Frame')" value="Zobrazit počet slov v článku" />
    </fieldset>
    <!-- There are some more fieldsets here and a submit button. -->
                  </div><!-- .data -->
              </form>
            </div><!-- tabcontent -->
</div><!-- /main -->
</body>
</html>

FCKeditor的SetHTML方法依赖于document.write调用来替换编辑控件中的内容。不幸的是,document.write不能在Firefox的Web控制台内工作。

这是一个已知的bug: Using document。在"便签本"窗口中写入时会在Web控制台出现"安全错误未定义"

我知道错误说Scratchpad和错误信息是不同的,但它是相同的问题。请注意David Chan (Mozilla安全研究员)的评论:

这似乎是在沙盒中运行WebConsole/ScratchPad的另一个错误。

你可能记得过去能够这样做的原因是因为它在FireBug中有效,在Chrome中也有效。您可能在过去使用FCKeditor控件时使用过这些环境之一。

非常确定这是一些跨域问题,您可能认为您在同一域上运行,但实际上不是。我将不得不检查实际的页面上运行的真正能够帮助你,但尝试加载所有相关的fckeditor文件使用相对文件路径(可选从根)和从不包括实际的域,这将防止很多麻烦一般(例如可能发生的事情是你在example.com上,但从www.example.com或类似的问题加载文件)。

奇怪的是,你不应该能够读取文件,然后,但触发的错误是关于非特权的操作,几乎总是跨域问题(或一些非常棘手的跨脚本上下文问题,但这些大多只相关,如果你开发的插件)。

如果你的javascript来自"http://webmaker.ooo.cz/…",那么这是可能的,你得到一个域名问题,如果你正在浏览的网站不同的子域比javascript被拉出。我不确定解决办法,我也不确定这就是问题所在。只是一种可能性。我建议试着把你正在使用的javascript与html页面只是为了确保代码本身实际工作。