Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

tinyMCE usage in HTML macro working only in PREVIEW mode

Tichomir Hadgiev
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 4, 2018 edited

Hi All, 

I'm trying to use tinyMCE within HTML macro and I'm stuck with a very strange problem. While not being a developer, but rather playing around, the problem I do encounter is that my script works in PREVIEW mode, but it doesn't work when I Save my work. 

Here is the script itself (APIkeyremoved on purpose): 

 

<button onclick="add_tiny(); return false;">CLICK ME TO INITIATE</button>
<textarea class="editor" id="one" name="content">1</textarea>

<script type="text/javascript" src="https://cloud.tinymce.com/stable/tinymce.min.js?apiKey=xxxxxxx"></script>
 
<script type="text/javascript">

tinymce.init({
    selector: ".editor",
    plugins: [
        "advlist autolink lists link image charmap print preview anchor",
        "searchreplace visualblocks code fullscreen",
        "insertdatetime media table contextmenu paste"
    ],
    toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});


function add_tiny () {
//console.log(tinymce.get('one').on("change", function() { alert("stuff"); }));
	console.log(tinymce.get("one").getContent());
}
</script>

 

The error in console I'm getting when page is saved is as follows: 

 

Uncaught TypeError: Cannot read property 'getContent' of undefined
at add_tiny (testing:861)
at HTMLButtonElement.onclick (testing:841)

 

 

 

Thanks a lot for your cooperation!

Regards, 

Tihomir

1 answer

0 votes
Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 5, 2018

How are you loading the script?  But I assume the issues is that you are running the code on the view of the page, but not actually changing the source of the page.

There is a separate process for installing plugins for TinyMCE and it involves writing a Confluence plugin. Fortunately, there is a tutorial.

https://developer.atlassian.com/server/confluence/enabling-tinymce-plugins/

Unfortunately, there is often a lot of assumed knowledge with building Confluence plugins.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, confluence whiteboards, whiteboard templates, template contest, visual collaboration, atlassian learning, confluence community, brainstorming tools, agile planning, team productivity, confluence templates, share your template

Share Your Confluence Whiteboard Template for a Chance to Be Featured in the Product! 🏆

Want to leave your mark on Confluence? One winner will have their whiteboard design added into Confluence for all users to access! This is your chance to showcase your creativity, help others, and gain recognition in the Confluence community.

Share your template today!
AUG Leaders

Atlassian Community Events