从插件对话框返回值

时间:2013-09-06 12:55:12

标签: tinymce

我添加了一个插件,用于在对话框窗口中打开html页面

// Adds a menu item to the tools menu
editor.addMenuItem('helloworld', {
    text: 'Example plugin',
    context: 'tools',
    onclick: function() {
        // Open window with a specific url
        editor.windowManager.open({
            title: 'TinyMCE sitfe',
            url: 'test.htm',
            width: 400,
            height: 300,
            buttons: [{
                text: 'Close',
                onclick: 'close'
            }]
        });
    }
});

test.htm看起来像这样:

<html>

<head>
</head>

<body>
    <input value="testing"></input>
</body>

</html>

我想在对话框关闭时添加一个将'testing'插入编辑器窗口的函数。与此问题非常相似: How do I get the values from my TinyMCE plugin back? 但是我无法打开他提供的链接。谢谢 -

2 个答案:

答案 0 :(得分:1)

好的,这篇文章让我在那里:

Get input field value from dialog box in TinyMCE

我修改了我的test.htm并且它可以正常工作

<html>

<head>
<script type="text/javascript" src="../compat3x/tiny_mce_popup.js"></script>


</head>

<body>
    <input id="image-url" value="testing"></input>
    <input id="submit-image-url" type="submit" value="Submit">
</body>
 <script>
    document.getElementById("submit-image-url").onclick = function(){
        var imageUrl = document.getElementById( 'image-url' ).value;

        window.parent.tinyMCE.activeEditor.execCommand( 'mceInsertContent', 0, imageUrl );
       tinyMCEPopup.close();
    };
</script>
</html>

答案 1 :(得分:1)

这是我用于tinyMCE 4的代码:

<script>
  function closeModalAndInsertText() {
    top.tinymce.activeEditor.selection.setContent('test');
    top.tinymce.activeEditor.windowManager.close();
  }
</script>