0

I am working on a WYSIWYG text editor and I'm using iframe as the textarea, i want the textarea to be selected as soon as the page loads. i tried the onload event and the focus() function but both didn't work.

here is the code:

<iframe name="richTextField" id="richTextField" style="border:#000000 1px solid; width:700px; height:300px;" ></iframe>

And the javascript

function iFrameOn(){
richTextField.document.designMode = 'On';
}
Kimimaruu
  • 3
  • 3
  • Is there any particular reason you're using iframes ? They're considered bad practice these days.. especially with input fields.. – Pogrindis Oct 09 '14 at 09:38
  • it is the first time i am making this, and in the tutorials i watched they used it. would a regular textarea be better? – Kimimaruu Oct 09 '14 at 09:39
  • Well possibly.. or even a DIV are you making one from scratch or implementing another library ? what is : `richTextField.document.designMode = 'On';` – Pogrindis Oct 09 '14 at 09:42
  • that makes it so that the iframe area is editable. – Kimimaruu Oct 09 '14 at 09:45
  • 1
    an Iframe is not an editable area.. Its a window to another page.. you will need to use an input textarea.. or you could use a div and construct an editable region within javascript.. The iframe would not be the correct approach. – Pogrindis Oct 09 '14 at 09:47
  • I am working with the execCommand for my bold/italic/underline and all other functions but a textarea doesn't support that. so i am supposed to use a div element, i am really bad at javascript could you maybe help me set up the base for this? – Kimimaruu Oct 09 '14 at 09:55

1 Answers1

0

A better approach is not to use IFrames.. They're not the most flexible when working with the DOM or any HTML elements.

A good approach is a element such as section without Javascript for the basics all you need is :

<section id="editable" contenteditable="true"></section>

Would be a simple example Fiddle

From here you can edit as you wish..

Because it has HTML markup you can have events (javascript) to append/ apply BOLD etc etc. All the WYSIWYG.

Good luck with your editor!

Pogrindis
  • 7,755
  • 5
  • 31
  • 44