【问题标题】:Getting specific content from TinyMCE editor从 TinyMCE 编辑器获取特定内容
【发布时间】:2015-10-15 01:59:50
【问题描述】:

我有一个为 wordpress 构建的插件,在用户选择该插件的选项后,它会在其中注入一个包含内容的短代码。我遇到的问题是tinyMCE.get('content').getContent() 当用户想要更新这些选项但使用它会拉出tinymce中的everything时调用它,我需要它限制在短代码打开和关闭标签内的内容.例如:在用户选择插件选项后,将创建一个短代码 [plugin]---HTML OPTIONS---[/plugin] 但是当调用 tinyMCE.get('content').getContent() 时,我需要它来获取所述插件标签内的所有内容,而没有其他类似的东西:[plugin]---GET THIS CODE----[/plugin] 任何帮助将感激不尽。如果您需要澄清任何事情,请告诉我。

【问题讨论】:

    标签: javascript jquery wordpress tinymce shortcode


    【解决方案1】:

    如果我了解您的尝试,那么您正在寻找的是 tinymce.dom.Selection 类(doc)

    更具体地说:

    // 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());
    

    您可以查看一些可用插件中的代码。 link 插件特别适用于文本选择。

    【讨论】:

    • 感谢 DFriend 的回复,但我认为要么我的代码错误,要么选择不是我想要的。当我将此代码添加到我的代码中时,它实际上会注入我在 setContent() 中放入的任何内容。所以如果我输入tinymce.activeEditor.selection.setContent('[fullwidth]Test[/fullwidth]');,那么编辑器现在就有了那个代码,这不是我想要的,因为它已经在那里了。我需要它来获取代码“[fullwidth]Test[/fullwidth]”并将其返回到其他地方。这有意义吗?
    • @ZacNespral21,是的,这是有道理的。要获取选择,请使用selection.getContent()。 Selection 类有许多方法来确定当前节点(元素)并设置元素周围的选择范围。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-10
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多