1

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

Ethan
  • 118
  • 1
  • 13

1 Answers1

0

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',
PDD
  • 71
  • 7
  • I tried doing that and I still get the same error ```Uncaught TypeError: Cannot read properties of null (reading 'getContent') at contact-us.html:62:43```` – Ethan Jul 22 '22 at 20:21
  • Show fragment at 62 line of the contact-us.html? And maybe you got any errors inside console? You tried to write `tinymce` inside console? Is it defined object? – PDD Jul 22 '22 at 20:26
  • This is what the line of code looks like console.log (tinymce.get("contact-text").getContent()) The fragment is .getContent()) – Ethan Jul 22 '22 at 20:47
  • @Ethan `contact-text` element after script or before? Also try to check what contact-text element is. Is it class name or id? And change `"contact-text"` to `".contact-text"` or `"#contact-text"` – PDD Jul 23 '22 at 10:47
  • The script tag is after the element. I also have tried selcting the element with .contact-text and #contact-text – Ethan Jul 23 '22 at 17:37
  • @Ethan open console in the browser and show me a log. Press F12, F5 before. And how much textarea tags on the page? – PDD Jul 24 '22 at 07:42
  • Problem migth be in referrer policy – PDD Jul 24 '22 at 07:57