I want to replace all {baseurl}
keywords to proper url in TinyMCE editor. How can i do that?
For example if user will add HTML in editor <img src="{baseurl}/image.jpg" />
i want to see this image in TinyMCE editor - so this will be replaced to <img src="http://mydomain.com
/image.jpg" />
Any ideas?
Here is the code that will replace your editor content. But you will need to do this action at the correct time.
var editor = tinymce.get('my_editor_id'); // use your own editor id here - equals the id of your textarea
var content = editor.getContent();
content = content.replace(/{\$baseurl}/g, 'http://mydomain.com');
editor.setContent(content);
With this solution I was able to modify the content on-the-fly, without replacing the content as whole:
tinymce.init({
setup: (editor)=>{
editor.on('init', ()=>{
$(editor.contentDocument).find('a').prop('title', 'my new title');
});
}
});
Maybe it helps someone :)
I used a very simple code working good with me
tinymce.get("page-content").setContent(''); // 'page-content' as the textarea id
tinymce.get("page-content").execCommand('mceInsertContent', !1, 'New content data');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With