I recently upgraded my version of TinyMCE* and discovered that this new version (4.9.11) does not return HTML when using tinymce.get("myUsercreatedID").getContent()
.
I tried tinymce.get("myUsercreatedID").getContent({format: 'html'})
but that did not work either.
How can I get the TinyMCE editor content as HTML?
* TinyMCE moved to a subscription service and has removed all old (free) versions from their website and from all web repositories. How very fair of them. However, I found NuGallery has archived copies of all versions if you download any nupkg (merely a zip file) and extract the content -> scripts -> tinymce folder.
It is not necessary to use .getContent()
to get the editor content.
TinyMCE’s editors are on the page, like any other HTML, and each TinyMCE editor is contained in an iframe. Each editor is directly accessible via the following method.
First, note that TinyMCE requires that you specify a unique ID for each editor – let us call this one “MyUniqueID” for this example.
const ifm = document.querySelector('iframe[id*=MyUniqueID_ifr]');
const innerDoc = ifm.contentDocument || ifm.contentWindow.document;
const myHtml = innerDoc.querySelector('body#tinymce').innerHTML;
console.log(myHtml);
NOTE THAT body#tinymce
is also user-specified. You might have named it tinyMCE
, in which case the string would be body#tinyMCE
— recall that JavaScript is case-sensitive.