简体   繁体   中英

TinyMCE getContent Returns Null

I'm trying to get the raw HTML out of TinyMCE editor. Here is the code I am using

      tinymce.init({
          selector: 'textarea',
          plugins: 'a11ychecker advcode casechange export formatpainter image editimage linkchecker autolink lists checklist media mediaembed pageembed permanentpen powerpaste table advtable tableofcontents tinycomments tinymcespellchecker',
          toolbar: 'a11ycheck addcomment showcomments casechange checklist code export formatpainter image editimage pageembed permanentpen table tableofcontents',
          toolbar_mode: 'floating',
          tinycomments_mode: 'embedded',
          tinycomments_author: 'Author name',

         
        });

        console.log (tinymce.get('content-text'))


In the console it says null. I have also used the active editor function.

console.log (tinymce.activeEditor.getContent())

Doing this gives me an error

Uncaught TypeError: Cannot read properties of null (reading 'getContent')
    at contact-us.html:62:43

I'm using TinyMCE version 6.1

Place the <script> to below the <textarea> and try again.

Or try to add ID onto textarea tag like

<textarea id="tinyarea">
...
</textarea>

and change selector in the js to

selector: 'textarea#tinyarea',

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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