IE9:设置document.domain时拒绝访问

时间:2012-05-02 14:32:53

标签: javascript internet-explorer dom same-origin-policy cleditor

在IE9上使用带有CLEditor的document.domain时遇到问题。当我添加document.domain时,我收到错误消息“SCRIPT5:访问被拒绝。”。它适用于Firefox以及删除document.domain时。我仍然没有使用跨子域iframe,所有iframe都在同一个域中。

如何修复它而不删除document.domain?

这是我如何设置document.domain:

  <script type="text/javascript" src="jquery-1.7.1.min.js"></script>
  <script type="text/javascript">
    document.domain = 'mydomain.com';
  </script>
  <script type="text/javascript" src="jquery.cleditor.js"></script>

这是CLEditor代码的一部分,其中出现错误:

      // Create a new iframe
    var $frame = editor.$frame = $('<iframe frameborder="0" src="javascript:true;" id="iframe">')
      .hide()
      .appendTo($main);

    // Load the iframe document content
    var contentWindow = $frame[0].contentWindow,
      doc = editor.doc = contentWindow.document,     // here is the error message
      $doc = $(doc);

以下是CLEditor的完整源代码:     http://premiumsoftware.net/cleditor/jquery.cleditor.js

1 个答案:

答案 0 :(得分:0)

要使用document.domain,需要将其设置为通信两侧的相同字符串 - 此处设置为iFrame和父级。

相关问题