简体   繁体   中英

Getting specific content from TinyMCE editor

I have a plugin im building for wordpress that injects a shortcode with content inside it after the user selects options for that plugin. What im having trouble with is tinyMCE.get('content').getContent() this is called when a user wants to update those options but using this pulls everything thats in tinymce, I need it limited to the content inside the shortcode open and close tags. For example: after a user selects options of the plugin, a shortcode of [plugin]---HTML OPTIONS---[/plugin] will be created but when tinyMCE.get('content').getContent() is called I need it to grab everything inside of said plugin tags and nothing else like so: [plugin]---GET THIS CODE----[/plugin] any help would be grateful. Let me know if you need clarification on anything.

If I understand what you are attempting then what you are looking for is the tinymce.dom.Selection class (doc)

More specifically:

// Sets some contents to the current selection in the editor
tinymce.activeEditor.selection.setContent('Some contents');

// Gets the current selection
alert(tinymce.activeEditor.selection.getContent());

You might take a look at code in some of the available plugins. The link plugin in particular works with text selections.

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