Pass contents of wysiwyg to variable


(Nic Hubbard) #1

I have been scratching my head about this for a few hours now, and I cannot figure it out.


I am needing to get get the contents of the wysiwyg editor and put that into a variable. I have gotten it to work for Mozilla browsers, as getting the contents from the iframe was easy:


       var summarytext = $('iframe:first').contents()[0].documentElement.innerHTML;
       var bodytext = $('iframe:last').contents()[0].documentElement.innerHTML;


But if the browser is not Mozilla, I need to get the contents from the editable region that the text is being typed into. I assumed that it was a div, but I have tried just about everything and I keep returning undefined.

So, could anyone shed some light onto this for me? Please?

(Greg Sherwood) #2

I haven't looked at the code for a long time now, but I know the HTML is stored inside a textarea and I think there is a function you can call in JS to get the WYSIWYG to write its current content into it. If you can call that (maybe it is not required) and then grab the content from the textarea, you should be laughing.


(Nic Hubbard) #3

Thanks Greg. Do you remember if that function is in one of the external .js file, or in the body of the page? Ha, there is alot of javascript for the wysiwyg.

(Greg Sherwood) #4

Got no idea sorry. It happens on form submit though, so you may want to search for "submit" :slight_smile:


(Greg Sherwood) #5

I've been having a bit more of a think about this. You should just be able to ask the editor for the content.


On the page, you'll see some JS like this:

<script type="text/javascript">

editor_xxx = new HTMLArea("<?php echo $this->name?>");

editor_xxx._createToolbar();

editor_xxx._createStatusBar();

editor_xxx.updateToolbar(false);



That object (editor_xxx) can be used to grab the content for both moz and IE. Just call editor_xxx.getHTML()


(Nic Hubbard) #6

[quote]I've been having a bit more of a think about this. You should just be able to ask the editor for the content.


On the page, you'll see some JS like this:

<script type="text/javascript">

editor_xxx = new HTMLArea("<?php echo $this->name?>");

editor_xxx._createToolbar();

editor_xxx._createStatusBar();

editor_xxx.updateToolbar(false);



That object (editor_xxx) can be used to grab the content for both moz and IE. Just call editor_xxx.getHTML()[/quote]



Thank you Greg!



This worked exactly how I wanted. And a bonus that I can use it for both Mozilla and IE.


(Greg Sherwood) #7

Good to hear.