简体   繁体   English

TinyMCE无法获取未定义或空引用的属性“ setContent”

[英]TinyMCE Unable to get property 'setContent' of undefined or null reference

I know this topic has been covered many times here but no matter which approach I take I either get a error such as "Unable to get property 'setContent' of undefined or null reference" or the line executes but nothing happens. 我知道这里已经讨论了很多主题,但是无论我采用哪种方法,我都会遇到诸如“无法获取未定义或空引用的属性'setContent'”之类的错误,或者该行执行但没有任何反应。

Here's what I know. 这就是我所知道的。 tinymce initializes and is a valid object. tinymce初始化并且是有效的对象。 The html variable has the propper HTML which it get from a parent window. html变量具有从父窗口获取的适当HTML。 jQuery is loaded and functional. jQuery已加载且功能正常。

In addition to the code below I have also tried. 除了下面的代码,我也尝试过。

tinyMCE.activeEditor.setContent(html);
tinymce.editors[0].setContent(html);
$('textarea#XRMeditor').val(html);  * Before initialization 

I have tried all methods before and after tinymce intializes (just in case). 我在tinymce初始化之前和之后尝试了所有方法(以防万一)。

<!DOCTYPE html>
<html>
<head>

          <script src="sage_jquery.min.js" type="text/javascript"></script>
          <script src="tinymce_/tinymce.min.js" type="text/javascript"></script>

  <script>
      var html = window.parent.document.getElementById("descriptionIFrame").contentDocument.getElementsByTagName('body')[0].innerHTML;
      debugger;
      //$('textarea#XRMeditor').val(html);
      tinymce.init({
          selector: 'textarea#XRMeditor'
});
      tinymce.get('XRMeditor').setContent(html);

  </script>
</head>
<body>
  <textarea id="XRMeditor">Easy (and free!) You should check out our premium features.</textarea>
</body>
</html>

I suspect this issue is that you are trying to talk to TinyMCE before its initialized on the page. 我怀疑这个问题是您试图在页面上初始化之前与TinyMCE进行交谈。

Your get() call is in the head of your page and I would doubt that when the browser processes your script that TinyMCE has initialized. 您的get()调用位于页面的顶部,我会怀疑当浏览器处理TinyMCE已初始化的脚本时。 You can use an "init" handler to delay when this call happens: 您可以使用“ init”处理程序来延迟此调用的发生时间:

tinyMCE.init({
  //your regular init parameters here...
  setup: function(editor) {
    editor.on('init', function() {
      //load your content here!
      tinymce.activeEditor.setContent(html);
      //or
      tinymce.editors[0].setContent(html);
    });
  }
});  

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

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