Hi, I am new here. Well, I made a rich text editor using IFrame and document.execcomand. All is ok, except I want to add something like displaying the HTML code of the text written in the IFrame to a div or a textarea.

For example, if someone has typed "Hello", and select it and click Bold, it will become bold. But the IFrame does not show: <strong>Hello</strong>, thus, I want to display the HTML as well in a textarea. How to do this?


You could use something like this:

var frame = document.getElementById("myIFrame"); // iFrame with the HTML
var div = document.getElementById("myDiv"); // div to show the HTML

div.innerText = frame.document.body.innerHTML; // Sets the Text of the div as the HTML of the frame.

Using innerText will not parse the HTML.

How about something like this...

    <div id="myDiv1"><b>text</b></div>
    <div id="myDiv2"></div>
var div1= document.getElementById("myDiv1");
var div2 = document.getElementById("myDiv2"); 
div2.innerText = div1.innerHTML;

thank you guys..yes it works now... i made my first open source rich text editor guys in fully javascript. it has its source preview, icons etc.. the source preview was the only thing i was confused. however, i have to say that i have to correct your codes. as far as i know, "innerText" does not work on Firefox. It works on the rest of browers. I used "textContent". My rich editor is only for HTML5 browsers. I dont support IE 8..too lame and will; give me heart attack... anyway, thank you...

Your are welcome, just mark the thread as solved please.

And if you can, I'd like to take a look at the editor.

the thread has been marked as solved..The editor will be exposed on the day I completed my website. Because Im doing more open source project. I want to make the web more free... the web should be open source... many people do not have the opportunity to take course, so, i decided to contribute. im myself a student but i work with the web since 3 years. if you can add me here, or leave me an email, it will be ok, so that i can let you know about the day the editor is revealed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.