1

Topic: IE: can't access editor instance functions

im trying to initialize an editor's content the moment the page is loaded. theres only one editor instance.
this is what i'm using:

tinyMCE.execInstanceCommand('mce_editor_0', 'mceInsertContent', false, 'content');

nothing happens in IE though (works fine in FF), and it seems the reason for it is the function can't find the 'mce_editor_0' instance or something like that.
i understand i can't directly do a

tinyMCE.setContent('content');

because no instance has been selected on page-load, therefore 'setContent()' wouldn't know where to put it. i figured using 'execInstanceCommand' would be the best way.
Any help would be greatly appreciated.  wink

2

Re: IE: can't access editor instance functions

As a matter of fact, I was trying to do the exact same thing with execCommand using mceFocus and mceInsertContent and could not get it to work.  I kept getting a pop-up warning for the mceInsertContent because mceFocus apparently didn't set the focus.  After reading your post I tried execInstanceCommand and so far it seems to work perfectly.

Here is my line of PHP:
window.opener.tinyMCE.execInstanceCommand('mce_editor_0', 'mceInsertContent', false, '".$record['Description']."');

I'm not sure what is wrong with your implementation, it seems like you are doing the same thing..

David

3

Re: IE: can't access editor instance functions

did you try that in IE?

4

Re: IE: can't access editor instance functions

here's an example of what i'm doing. i wonder where i'm screwing up.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<!-- tinyMCE -->
<script language="javascript" type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
    tinyMCE.init({
        mode : "textareas"
    });

    function initialise() {
        var t = document.getElementById("mce_editor_0");
        if (t) {
            alert('ok');
        } else {
            alert('doh!');
        }
        tinyMCE.execCommand('mceFocus', false, 'mce_editor_0');
    }
</script>
<!-- /tinyMCE -->
</head>

<body onLoad="initialise()">
<textarea id="harr" rows="25" cols="80"></textarea>
</body>
</html>

5

Re: IE: can't access editor instance functions

one thing i noticed just now is that while the alert box is being displayed, in IE the tinyMCE editor hasn't been loaded yet, all you see is the normal textarea. so naturally, the html elements which belong to tinymce aren't there yet. in firefox, though, the editor is already loaded up. so i guess the solution would be to change the call for 'initialise()' to somwhere else. the problem is where. there might be some other way to fix this, i don't really know.

6

Re: IE: can't access editor instance functions

Yes, the problem here is that the editor gets initialized on page load. When the onload event triggers, so if you try to execute commands then the editor instance by that name won't exists just yet.

I suggest that you have a look at the setupcontent_callback option to solve this.

Here is a example how to use that in your code:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<!-- tinyMCE -->
<script language="javascript" type="text/javascript" src="../jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
   tinyMCE.init({
      mode : "textareas",
      setupcontent_callback : "initialise"
   });

   function initialise(editor_id, body_node) {
      tinyMCE.execCommand('mceFocus', false, editor_id);
   }
</script>
<!-- /tinyMCE -->
</head>

<body>
<textarea id="harr" rows="25" cols="80"></textarea>
</body>
</html>
Best regards,
Spocke - Main developer of TinyMCE

7

Re: IE: can't access editor instance functions

I found that the problem only existed, in IE, when I tried to set the height and width.  I deleted the Height and width and set the textarea to 100% and all was well.  Except, now I get a JS error for the save button:)