Joe Riggs
Joe Riggs

Reputation: 1324

Return Value From Plugin Dialog

I have added a plugin to open a html page in a dialog window

// 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 looks like this:

<html>

<head>
</head>

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

</html>

I would like to add a function that inserts 'testing' into the editor window when the dialog is closed. Very similar to this question: How do I get the values from my TinyMCE plugin back? however I was unable to open the links he provided. Thanks-

Upvotes: 2

Views: 3150

Answers (2)

Chris
Chris

Reputation: 2046

Here's the code that I used for tinyMCE 4:

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

Upvotes: 1

Joe Riggs
Joe Riggs

Reputation: 1324

OK, this post got me there:

Get input field value from dialog box in TinyMCE

I modified my test.htm to this and it works

<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>

Upvotes: 1

Related Questions