简体   繁体   中英

can I add onclick event on elements in CKEDITOR?

In the ckeditor, we have two editing modes (source view and WYSiWYG view)

We can (of cause) add any html codes in source view mode. But in WYSiWYG mode, we only play with toolbar and allowed properties. For those who are not familiar with HTML, I try to find ways to help them to define events on elements in the editor (such as onclick="alert('test');" ).

Are there any ways to do this?

in the case of image, we can specify id, title, style and class in ckeditor. But that's all. If there is a way to add or enable more properties in something like config.js, that would be very good.

Thanks in advance

KS from Korea.

take a look at answers for this question . i think it would be pretty simple, if i'm interpreting your question correctly.

customize the dialogs during the define, add a "onclick" field and then set and get the contents in the setup and commit functions.

also look at the caveat about how html is handled during the getData, that might create issue if onclick isn't valid.. (i've never added anything but valid html attributes, and saw other questions where that created problems)

look at ckeditor/_samples/api_dialog.html for background on modifying dialogs.

I have created a dialog plugin that will add an onclick event by following and modifying the code found in the tutorial "Creating a Simple CKEditor Plugin" tutorials, parts 1 and 2 (found here ). After you have created an element to insert into ckeditor, you can add an onclick event by inserting the line of code

element.setAttribute('onclick','fuu()');

This will make more sense once you have read through the tutorial.

The one problem with this method is that you cannot change this value through reopening the dialog box through a context menu, and I am not sure why.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM