Wraping selection with tag

Last post 10-18-2005, 5:17 PM by ngaudreau. 4 replies.
Sort Posts: Previous Next
  •  10-09-2005, 6:56 AM 11557

    Wraping selection with tag

    How can i design special button so the selected text (into the edit box) will wrap with my own tags, and if there is not selection, just insert  the open tag?
    The solution should be compatible with IE and FireFox.
    I guess there is internal function for this task, because many standrad buttons doing that (Bold, Italic and etc.), But I can't find any documentation.
  •  10-10-2005, 5:55 AM 11562 in reply to 11557

    Re: Wraping selection with tag

    I find part of the solution.

    For IE:
            editor.setFocus();
            var txt = editor.getSelection().htmlText;
            if (txt != "")
                editor.getSelection().pasteHTML("<tag>"+txt+"</tag>");
            else
                editor.getSelection().pasteHTML("<tag>");

    For FireFox:
        var sel = editor.frame.contentWindow.getSelection();
        var txt = sel.getRangeAt(0);
        if (txt != "")
            editor.insertHTML("<tag>"+txt+"</tag>");
        else
            editor.insertHTML("<tag>");

    I still have two problems:
    1. When selection is empty, the editor insert also the closing tag ("</tag>"). But i need just the opening tag, so the following text will effect from the tag. (My tag is <div...> with some properties).
    2. I need way to identify the browser, prefer by functionality, not HTTP Header.
  •  10-10-2005, 12:40 PM 11575 in reply to 11562

    Re: Wraping selection with tag

    Moshe,
     
    Where did you find this code?  I have been looking for the same thing because I want to do a similar type of operation where I enter my own tags.
     
    Thanks,
    Nathan
  •  10-12-2005, 1:11 PM 11678 in reply to 11575

    Re: Wraping selection with tag

     ngaudreau wrote:
    Moshe,
     
    Where did you find this code?  I have been looking for the same thing because I want to do a similar type of operation where I enter my own tags.
     
    Thanks,
    Nathan
     
    Any help would be appreciated, thanks.
  •  10-18-2005, 5:17 PM 11821 in reply to 11678

    Re: Wraping selection with tag

    Anyone else know where I can find this code?
View as RSS news feed in XML