Rich text editor

Discussion in 'Javascript' started by Prasad, Nov 24, 2006.

  1. Prasad

    Prasad Guest

    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,
    Prasad, Nov 24, 2006
    #1
    1. Advertising

  2. Prasad

    Prasad Guest

    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.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
    ..
    Prasad, Nov 25, 2006
    #2
    1. Advertising

  3. Prasad

    Prasad Guest

    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.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 key is pressed
    > .


    Hi all, any workaround here ??
    Or can I atleast know that "Enter key " is pressed while entering data
    into the editor ???
    Prasad, Nov 27, 2006
    #3
  4. Prasad

    marss Guest

    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>
    >
    marss, Nov 27, 2006
    #4
  5. Prasad

    Dylan Parry Guest

    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.
    Dylan Parry, Nov 27, 2006
    #5
  6. Prasad

    Prasad Guest

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




    > > }
    > > displayEditor("editor", "html", 250, 200) ;
    > > </script>
    > >
    Prasad, Nov 27, 2006
    #6
  7. Prasad

    Prasad Guest

    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.
    Prasad, Nov 27, 2006
    #7
  8. Prasad

    Prasad Guest

    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.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
    >
    >
    > > > }
    > > > displayEditor("editor", "html", 250, 200) ;
    > > > </script>
    > > >
    Prasad, Nov 28, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marina
    Replies:
    1
    Views:
    458
    Tim Heuer
    Jul 11, 2003
  2. VB Programmer
    Replies:
    2
    Views:
    621
  3. VB Programmer
    Replies:
    2
    Views:
    757
    CuteSoft
    Dec 29, 2004
  4. Eirik Eldorsen

    Recommended rich text editor

    Eirik Eldorsen, Jan 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    325
    Eirik Eldorsen
    Jan 18, 2005
  5. Hollow Quincy

    rich:dataTable - rich:dataScroller

    Hollow Quincy, Dec 30, 2011, in forum: Java
    Replies:
    5
    Views:
    4,476
    Arved Sandstrom
    Jan 2, 2012
Loading...

Share This Page