If using popup window, you may use:
tinyMCEPopup.editor.execCommand('mceInsertLink', false, 'some content goes here');
// mceInsertLink inserts the content at the current cursor or caret position.
// If the editor is not on focus, the insertion will be at the very first line content in the editor.
If you want to insert HTML tags and javascript variables, you may use, for example:
<script type='text/javascript'>
var my_var= "some value";
var my_var_two = 99;
tinyMCEPopup.editor.execCommand('mceInsertLink', false,
'<span >[' + my_var + ', ' + my_var_two + ']</span>');
tinyMCEPopup.close(); // too close the popup window
</script>
If you are in a PHP file, you may use the same strategy, just use PHP instead of JavaScript, for example:
<script type='text/javascript'>
tinyMCEPopup.editor.execCommand('mceInsertContent', false,
'<span >[' + <?php echo $my_php_var; ?> +']</span>');
</script>
You can also assign PHP variables (assuming you are in .php file) to Javascript variables and use them in the editor content insertion, for example:
<script type='text/javascript'>
var my_var= "<?php echo $my_php_var; ?>";
var my_var_two = "<?php echo $my_php_var_two_or_a_function_call; ?>";
tinyMCEPopup.editor.execCommand('mceInsertLink', false,
'<span >[' + my_var + ', ' + my_var_two + ']</span>');
tinyMCEPopup.close(); // too close the popup window
</script>