Getting HTML editor content (value) dynamically

Getting HTML editor content (value) dynamically

Karen Stepanyan གིས-
Number of replies: 8

I'm using HTML editor in one of custom modules I have recently added.

I can easily get the typed/edited content of the editor when the form data is submitted (i.e. _POST["HTMLEditor"]), however I have problem trying to get its content without submiting the form.

I use (JavaScript) "document.forms[0].textarea.value" and get empty string despite the fact that HTML editor contains edited text.

How can I get the content of the  HTML Editor by using Javascript without submitting the from data?

Thank you in advance...

དཔྱ་སྙོམས་ཀྱི་སྐུགས་ཚུ།: -
In reply to Karen Stepanyan

Re: Getting HTML editor content (value) dynamically

Janne Mikkonen གིས-
Core developers གི་པར
The problem is that the editor is not "really" in the page, but in memory and it isn't textarea field at all. It's an iframe. So you can't use document.forms[0].textarea.value

So here's how you get the text from the editor:

if (window.frames.length > 0) {
    // editor is loaded
    yourfield.value = frames[0].document.body.innerHTML;
}


As you can see you'll have to use innerHTML to get the text. And just for a tip, if you have several editors at one page IE counts iframes from top to bottom and Mozilla/Firefox counts them from bottom to top.

Hope this helps.

- Janne -
In reply to Janne Mikkonen

Re: Getting HTML editor content (value) dynamically

Crescenciano Olvera གིས-

Hi Janne,

I am looking in the moodle forums some help and I found your post, from some time ago, I tried to insert a htm file inside a lesson, you can see my post in: http://moodle.org/mod/forum/discuss.php?d=13256#71046

The code that I was used is:

<p align="center"><iframe src="http://sintegralesa.org/Anim_JS/mem_EH.htm" width="600" height="450" /></p>

But it partially work, the code insert the file in the lesson edit mode and I can see it, but when I close the editor mode, the file do not appear in the instructor and neither in the student screens.

Could you give some advice for this problem?

I will appreciate your answer.

SALUDOS,

Crescenciano.

In reply to Crescenciano Olvera

Re: Getting HTML editor content (value) dynamically

Janne Mikkonen གིས-
Core developers གི་པར
Hi Crescenciano.

Actually this has nothing to do with the editor it self. The problem is that the iframe element is not in Moodle's allowed tags list, so it'll get stripped out from output.

You can try override it by adding <iframe> element in the allowed tag list in weblib.php file (not recommended, it'll open a huge security hole).

Cheers,
Janne
In reply to Janne Mikkonen

Re: Getting HTML editor content (value) dynamically

Crescenciano Olvera གིས-

Hi Janne,

Thank you for your answer,

At the first time, I am trying to insert a htm files produced with Dreamweaver from Macromedia, this has some code pieces with behavoirs included, nothing special, only some frames to present to the student information based in some buttons that they choose, for instance a left menu frame with the items to see in a lesson, and showing the information, in a rigth frame inside the lesson too, according to the studen choosed options.

And at this moment I would like to embed in a lesson some pieces of javascript code, because I am trying to use this to include games like memory, search words, etc.

Do you think that is possible insert within a moodle lesson some code for that? and, How can I do this?

Thank you in advance...

Crescenciano.

In reply to Janne Mikkonen

Re: Getting HTML editor content (value) dynamically

daniel ginerman གིས-
hi Janne.... I'm having this very problem when trying to include a huge new tool (a microbrowser inside the page, provided for free by turnstyle.com; a kind of picture-in-picture for the web).... the "iframe" code gets stripped inmediately when I upload it from the html editor.
could you please specify to me how adding the iframe to the weblib.php will make a serious security hole, and if you have any idea, how to fix it in an other way instead of remaining without this tool?
thanx in advance,

daniEl
http://eduplanet.net/

In reply to daniel ginerman

Re: Getting HTML editor content (value) dynamically

Janne Mikkonen གིས-
Core developers གི་པར
Hi Daniel,

Since the source document of that iframe can come from anywhere and that's the security hole. It's very easy to add webpage location into iframe that include some malicious scripts. So use at your own risk...

- Janne -
In reply to Janne Mikkonen

can't embed a video in a forum post - now in 1.7 - can you help pls?

daniel ginerman གིས-
hi people,
long time has passed since we had that problem in 1.4.3. then, it was enough to add the iframe, object, embed tags to the allowed ones in weblib.php
i tried the same in my 1.7 installation at galeinai.net, but the results were errors in dmllib.php and weblib.php, and the forum stopped to work.
i'm trying to do something innocent: i want to embed videos in one forum, to have it working as a vodcast-alike.
the code I inserted was: "
(center)(embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=-92892846090506216&hl=en" flashvars="")(/embed)(br)YodTeth Kislev 5767- Hisvaadus Rav Yitzchak Ginsburgh shlit"a in Jerusalem - part 3 (/center)" --- (i'm sustituing <> for () with the hope of having this code displayed here.
but when I see the post, it only has the text portion; when I edit it, all the (embed)(/embed) has dissapeared.
please, what do I have to change in any configuration file to have the possibility of embedding in my forum posts enabled?
thanx in advance,

daniEl