By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,533 Members | 1,497 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,533 IT Pros & Developers. It's quick & easy.

Rich text editor

P: n/a

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.docu ment;

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,

Nov 24 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a

Prasad wrote:
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.docu ment;

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
..

Nov 25 '06 #2

P: n/a

Prasad wrote:
Prasad wrote:
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.docu ment;

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 key is pressed
.
Hi all, any workaround here ??
Or can I atleast know that "Enter key " is pressed while entering data
into the editor ???

Nov 27 '06 #3

P: n/a

Prasad wrote:
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'");
});

}
displayEditor("editor", "html", 250, 200) ;
</script>
Nov 27 '06 #4

P: n/a
Prasad wrote:
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.
Nov 27 '06 #5

P: n/a

marss wrote:
Prasad wrote:
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'");
});

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.ad dEventListener("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!

}
displayEditor("editor", "html", 250, 200) ;
</script>
Nov 27 '06 #6

P: n/a

Dylan Parry wrote:
Prasad wrote:
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 ;)

--
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..
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.
Nov 27 '06 #7

P: n/a

Prasad wrote:
marss wrote:
Prasad wrote:
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'");
});

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.ad dEventListener("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
>
}
displayEditor("editor", "html", 250, 200) ;
</script>
>
Nov 28 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.