1

I would like to add a clickable button/image/div inside the html editor (not the navigation bar). But when I use the onBeforeSetContent.add function to filter content and add an element with an onclick tag, this tag gets stripped.

This is all done via a tinymce plugin btw since I'm using Wordpress.

//replace shortcode before editor content set
ed.onBeforeSetContent.add(function(ed, o) {
    o.content = t.filter_content(o.content);
});

...

filter_content : function(co) {
    return co.replace(/\[icitspot([^\]]*)\]/g, function(a,b){
        return '<img src="#" onclick="alert(\'abc\')" class="wpSpot mceItem" title="clickme" />';
    });
},

2 Answers 2

3

Instead of using the onclick attribute, click events should be detected in general:

ed.onClick.add(function(ed, e) {
    console.log(e.target);
});

Now you can detect the element that was clicked and determine if it's your button/div.

Sign up to request clarification or add additional context in comments.

Comments

1

Either use your own solution or you will have to specify onclick as a valid attribute to prevent the stipping of this attribute using the tinymce valid_elements setting.

Example:

valid_elements: "@[id|class|title|style|onmouseover|onclick]," +
"a[name|href|target|title|alt]," +
"#p,blockquote,-ol,-ul,-li,br,img[src|height|width],-sub,-sup,-b,-i,-u," +
"-span[data-mce-type],hr",

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.