Rich text editor

P

Prasad

Hi all, I am trying to develop a simple rich text editor
I do only require bold, itlaic, underline..

The code for IE is

<script>
function displayEditor(editor, html, width, height)
{

document.writeln('<iframe id="' + editor + '" name="' + editor +
'" width="' + width + 'px" height="' + height + 'px"></iframe>');

var mainContent= '<html id="' + editor + '"><head></head><body
onkeypress=alert("Hi")>"' + html + '"</body></html>' ;
var edit = document.getElementById(editor).contentWindow.document;

edit.write(mainContent);

edit.designMode = "On" ;

}
displayEditor("editor", "html", 250, 200) ;
</script>

"You can use Ctrl+B to bold, Ctrl+U to underline, Ctrl+I for Italic "

Its working fine but I wanted to know which key is pressed .
For this, I have written onkeypress event in the body tag .
But that event is not geing fired .

So what should I do here to know which key is pressed ?

Please help me out ..

Thanx in advance,
 
P

Prasad

Prasad said:
Hi all, I am trying to develop a simple rich text editor
I do only require bold, itlaic, underline..

The code for IE is

<script>
function displayEditor(editor, html, width, height)
{

document.writeln('<iframe id="' + editor + '" name="' + editor +
'" width="' + width + 'px" height="' + height + 'px"></iframe>');

var mainContent= '<html id="' + editor + '"><head></head><body
onkeypress=alert("Hi")>"' + html + '"</body></html>' ;
var edit = document.getElementById(editor).contentWindow.document;

edit.write(mainContent);

edit.designMode = "On" ;

}
displayEditor("editor", "html", 250, 200) ;
</script>

"You can use Ctrl+B to bold, Ctrl+U to underline, Ctrl+I for Italic "

Its working fine but I wanted to know which key is pressed .
For this, I have written onkeypress event in the body tag .
But that event is not geing fired .

So what should I do here to know which key is pressed ?

Please help me out ..

Thanx in advance,


Please help me out here , I could not move anywhere until & unless I
solve this ..
If what I required is not possible , can any suggest a new method
which creates a simple editor and helps to know which is key is pressed
..
 
P

Prasad

Prasad said:
Please help me out here , I could not move anywhere until & unless I
solve this ..
If what I required is not possible , can any suggest a new method
which creates a simple editor and helps to know which key is pressed
.

Hi all, any workaround here ??
Or can I atleast know that "Enter key " is pressed while entering data
into the editor ???
 
M

marss

Prasad said:
edit.write(mainContent);

edit.designMode = "On" ;

Hi,
Try to add here next code:
edit.attachEvent("onkeypress", function(event){
if (event.keyCode == 13)
alert("You pressed 'Enter'");
});
 
D

Dylan Parry

Prasad said:
Hi all, I am trying to develop a simple rich text editor

Are you doing this because you require a rich text editor, and don't
know of any existing ones? Or are you doing this because you *want* to
do it?

If the answer to the first question is "yes", then I'd suggest you don't
reinvent the wheel ;)

--
Dylan Parry
http://electricfreedom.org | http://webpageworkshop.co.uk

Programming, n: A pastime similar to banging one's head
against a wall, but with fewer opportunities for reward.
 
P

Prasad

marss said:
Hi,
Try to add here next code:
edit.attachEvent("onkeypress", function(event){
if (event.keyCode == 13)
alert("You pressed 'Enter'");
});

Ohhhhhh
It's working................
I am very much thankful to you ..
Its working in IE
and for Mozilla I changed to :
document.getElementById(editor).contentDocument.addEventListener("onkeypress",
function(event){
if (event.keyCode == 13)
alert("You pressed 'Enter'");
},false);
But its not working ..
Any thing wrong in the code?????

Thanx once again!



 
P

Prasad

Dylan said:
Are you doing this because you require a rich text editor, and don't
know of any existing ones? Or are you doing this because you *want* to
do it?

If the answer to the first question is "yes", then I'd suggest you don't
reinvent the wheel ;)

--

Yes .. I require a rich text editor and but also I know of existing
ones ..
But I want my editor to be very simple as above..(FYI, I am not
reinventing the wheel .. I took the the existing code and modified it
as above to make it simple)..

So I "want" to do this..
 
P

Prasad

Prasad said:
Ohhhhhh
It's working................
I am very much thankful to you ..
Its working in IE
and for Mozilla I changed to :
document.getElementById(editor).contentDocument.addEventListener("onkeypress",
function(event){
if (event.keyCode == 13)
alert("You pressed 'Enter'");
},false);
But its not working ..
Any thing wrong in the code?????
Thanx once again!


Sorry ! it's coming for mozilla too
I used event type "onkeypress" instead of " keypress"
Thanx alot for helping me out
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top