I am creating an instant messenger chat application. I have a roster
window, and when I click on a member of the roster to send them a
message it opens a chat window. I use the function below to create the
chat window. This function returns an object with references to all
the elements I need to work with. Every browser seems to work fine,
except of course for Internet Explorer. IE won't let me insert
anything into the elements. I could, oddly enough get it to allow me
to set the text of an element, but I couldn't get the elements to
adopt any new elements. Not sure if this is enough information, but I
would appreciate any help anyone can give.

function buildChatWindow(recipient)
{
        /** open a new window for the chat application */
        if (!chatWindow || chatWindow.closed){
                /** create the window */
                chatWindow = window.open('', 'IV5_Chat',
'scrollbars=1,toolbar=0,menubar=0,resizable=1,status=0,location=0,left=250,top=50,width=500,height=400');

                /** get the document */
                doc = chatWindow.document;
                doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd"><html xmlns="http://www.w3.org/1999/
xhtml"><head><meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" /><title>IV5 Chat</title><!-- Load Chat Styles And
Javascript --><link rel="stylesheet" media="screen" type="text/css"
href="/css/IV5.css" /><link rel="stylesheet" media="all" type="text/
css" href="/apps/Chat/Assets/css/Chat.css" /></head><body><div
id="Chat_ListArea"><ul id="Chat_List"></ul></div><div
id="Chat_MessageArea"></div><div id="Chat_TextArea"><textarea
id="Chat_Text" cols="1" rows="2"></textarea><input type="hidden"
id="Chat_Recipient" value="" /></div></body></html>');
                doc.close();
        } else doc = chatWindow.document;

        /** give the window focus */
        chatWindow.focus();

        /** get the element references */
        head = $(doc.getElementsByTagName('head')[0]);
        title = $(doc.getElementsByTagName('title')[0]);
        body = $(doc.getElementsByTagName('body')[0]);
        chatListArea = $(doc.getElementById('Chat_ListArea'));
        chatList = $(doc.getElementById('Chat_List'));
        chatMessageArea = $(doc.getElementById('Chat_MessageArea'));
        chatTextArea = $(doc.getElementById('Chat_TextArea'));
        chatText = $(doc.getElementById('Chat_Text')).removeEvents().addEvent
('keypress', function(e){
                event = new Event(e);
                if (!event.shift && event.key == 'enter' && this.value.length > 
0){
                        sendMessage(chatRecipient.value, chatText.value, 
chatMessageArea);
                }
        }).addEvent('keyup', function(e){
                event = new Event(e);
                if (!event.shift && event.key == 'enter' && this.value.length > 
0)
this.value = '';
        });
        chatRecipient = $(doc.getElementById('Chat_Recipient'));

        /** check for recipient */
        if (recipient) chatRecipient.value = recipient;

        /** set the focus on the textarea */
        (function(){ chatText.focus(); }).delay(1000);

        /** return the parts */
        return {'head': head, 'title': title, 'body': body, 'chatListArea':
chatListArea, 'chatList': chatList, 'chatMessageArea':
chatMessageArea, 'chatTextArea': chatTextArea, 'chatText': chatText,
'chatRecipient': chatRecipient};
}

Reply via email to