Ajax seems to kill IE

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Technocrat
Forum Contributor
Posts: 127
Joined: Thu Oct 20, 2005 7:01 pm

Ajax seems to kill IE

Post by Technocrat »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have a simple 2 way ajax chat system. Basically it's to allow someone to have 1 on 1 conversations with multiple people. It works fine in FF and Opera but for some reason in IE after a period of time, about 20-30 minutes, IE will stop loading the page. You can't even browse to the page any more. The only way to fix the issue is to restart IE.

I can't figure out why. It's like the pipe I make to the server do not close and keep recreating themselves over and over until IE fails.

[syntax="javascript"]var updateInterval = 1000;
var users_content;
var chat_text;
var chat_content;
var buttons;
var xmlHttpGetUsers = createXmlHttpRequestObject();
var xmlHttpGetChats = createXmlHttpRequestObject();
var xmlHttpGetButtons = createXmlHttpRequestObject();
var xmlHttpGetSendMessage = createXmlHttpRequestObject();
var timer_chats;
var isDown = false;

function createXmlHttpRequestObject() {
    // will store the reference to the XMLHttpRequest object
    var xmlHttp;
    // this should work for all browsers except IE6 and older
    try {
        // try to create XMLHttpRequest object
        xmlHttp = new XMLHttpRequest();
    } catch(e) {
        // assume IE6 or older
        var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                        "MSXML2.XMLHTTP.5.0",
                                        "MSXML2.XMLHTTP.4.0",
                                        "MSXML2.XMLHTTP.3.0",
                                        "MSXML2.XMLHTTP",
                                        "Microsoft.XMLHTTP");
        // try every prog id until one works
        for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
            try {
                // try to create XMLHttpRequest object
                xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
            } catch (e) {}
        }
    }
    // return the created object or display an error message
    if (!xmlHttp) {
        alert("Error creating the XMLHttpRequest object.");
    } else {
        return xmlHttp;
    }
}

/*=== Users ====*/
function requestUsers() {
    //Random number of IE
    var ran_number = Math.random()*5;
    //URL to go to
    var url = 'get_users.php?my='+my+'&type='+u_type+'&get_users=1&trash='+ran_number;

    if(xmlHttpGetUsers) {
        try {
            // don't start another server operation if such an operation
            // is already in progress
            if (xmlHttpGetUsers.readyState == 4 || xmlHttpGetUsers.readyState == 0) {
                // call the server page to execute the server-side operation
                xmlHttpGetUsers.open("GET", url, true);
                xmlHttpGetUsers.onreadystatechange = handleReceivingUsers;
                xmlHttpGetUsers.send(null);
            } else {
                // we will check again for new users
                setTimeout("requestUsers();", updateInterval);
            }
        } catch(e) {
            displayError(e.toString());
        }
    }
}

function handleReceivingUsers() {
    // continue if the process is completed
    if (xmlHttpGetUsers.readyState == 4) {
        // continue only if HTTP status is "OK"
        if (xmlHttpGetUsers.status == 200) {
            try {
                // process the server's response
                readUsers();
            } catch(e) {
                // display the error message
                displayError(e.toString());
            }
        } else {
            // display the error message
            displayError(xmlHttpGetUsers.statusText);
        }
    }
}

function readUsers() {
    // retrieve the server's response
    var response = xmlHttpGetUsers.responseText;
    //Clear the users
    users_content.innerHTML = '';

    //If there is an error
    if (response.indexOf("ERRNO") >= 0 || response.indexOf("error:") >= 0 ) displayError('Sever Error '+response);
    //If there is no data
    if (response.length == 0) {
        setTimeout("requestUsers();", updateInterval);
        return;
    }

    //Set the users HTML to the response
    users_content.innerHTML = response;
    //Reset the timer
    setTimeout("requestUsers();", updateInterval);
}

/*=== Chats ===*/
function requestChats() {
    //Random number of IE
    var ran_number = Math.random()*5;
    //URL to go to
    var url = 'chat.php?last_chat='+last_chat+'&sid='+chat_id+'&type='+u_type+'&my='+my+'&trash='+ran_number;

    if(xmlHttpGetChats) {
        try {
            // don't start another server operation if such an operation
            // is already in progress
            if (xmlHttpGetChats.readyState == 4 || xmlHttpGetChats.readyState == 0) {
                // call the server page to execute the server-side operation
                xmlHttpGetChats.open("GET", url, true);
                xmlHttpGetChats.onreadystatechange = handleReceivingChats;
                xmlHttpGetChats.send(null);
            } else {
                // we will check again for new messages
                timer_chats = setTimeout("requestChats();", updateInterval);
            }
        } catch(e) {
            displayError(e.toString());
        }
    }
}

function handleReceivingChats() {
    // continue if the process is completed
    if (xmlHttpGetChats.readyState == 4) {
        // continue only if HTTP status is "OK"
        if (xmlHttpGetChats.status == 200) {
            try {
                // process the server's response
                readChats();
            } catch(e) {
                // display the error message
                displayError(e.toString());
            }
        } else {
            // display the error message
            displayError(xmlHttpGetChats.statusText);
        }
    }
}

function readChats() {
    // retrieve the server's response
    var response = xmlHttpGetChats.responseText;

    //Split the response
    var ret = new Array(2);
    ret = get_last_chat(response);
    response = ret[0];
    last_chat = ret[1];

    if (response.indexOf("ERRNO") >= 0 || response.indexOf("error:") >= 0 ) displayError('Sever Error '+response);
    if (response.length <= 1) {
        timer_chats = setTimeout("requestChats();", updateInterval);
        return;
    }

    chat_content.innerHTML = chat_content.innerHTML + response;
    chat_content.scrollTop = chat_content.scrollHeight;
    timer_chats = setTimeout("requestChats();", updateInterval);
}

/*=== Send Chat ===*/
function send_chat_text() {
    //Random number of IE
    var ran_number = Math.random()*5;
    //URL to go to
    //We encode it in base 64 just to make sure that nothing gets lost in translation
    var url = 'chat.php?my='+my+'&type='+u_type+'&text='+ encode(chat_text.value) +'&chat_id=' +chat_id+'&trash='+ran_number;

    //Clear the text area
    chat_text.value ='';
    chat_text.focus();
    //Send the command
    if(xmlHttpGetSendMessage) {
        try {
            // don't start another server operation if such an operation
            // is already in progress
            if (xmlHttpGetSendMessage.readyState == 4 || xmlHttpGetSendMessage.readyState == 0) {
                // call the server page to execute the server-side operation
                xmlHttpGetSendMessage.open("GET", url, true);
                xmlHttpGetSendMessage.send(null);
            }
        } catch(e) {
            displayError(e.toString());
        }
    }
}

/*=== Buttons ===*/
function requestButtons() {
    var ran_number = Math.random()*10;
    var url = 'get_buttons.php?sid='+chat_id+'&my='+my+'&type='+u_type+'&trash='+ran_number;

    // only continue if xmlHttpGetMessages isn't void
    if(xmlHttpGetButtons) {
        try {
            // don't start another server operation if such an operation
            // is already in progress
            if (xmlHttpGetButtons.readyState == 4 || xmlHttpGetButtons.readyState == 0) {
                // call the server page to execute the server-side operation
                xmlHttpGetButtons.open("GET", url, true);
                xmlHttpGetButtons.onreadystatechange = handleReceivingButtons;
                xmlHttpGetButtons.send(null);
            }
        } catch(e) {
            displayError(e.toString());
        }
    }
}

function handleReceivingButtons() {
    // continue if the process is completed
    if (xmlHttpGetButtons.readyState == 4) {
        // continue only if HTTP status is "OK"
        if (xmlHttpGetButtons.status == 200) {
            try {
                // process the server's response
                readButtons();
            } catch(e) {
                // display the error message
                displayError(e.toString());
            }
        } else {
            // display the error message
            displayError(xmlHttpGetButtons.statusText);
        }
    }
}

function readButtons() {
    // retrieve the server's response
    var response = xmlHttpGetButtons.responseText;

    if (response.indexOf("ERRNO") >= 0 || response.indexOf("error:") >= 0 ) displayError('Sever Error '+response);
    if (response.length == 0) {
        return;
    }

    buttons.innerHTML = response;
}

/*=== Other Functions ===*/

// function that displays an error message
function displayError(message) {
    alert("Error accessing the server! "+ "\r\n" + message);
}

function get_last_chat(Request) {
    var ret = new Array(2);
    loc = Request.indexOf('<last_chat>');
    loc2 = Request.indexOf('</last_chat>');
    if ((loc-1) <= 0) {
        ret[0] = '';
    } else {
        ret[0] = Request.substring(0, loc-1);
    }
    ret[1] = Request.substring(loc+11, loc2);
    return ret;
}

function keydown(e) {
    var characterCode; //literal character code will be stored in this variable
    e = (!e) ? window.event : e;

    characterCode = (e.charCode) ? e.charCode :
         ((e.keyCode) ? e.keyCode :
         ((e.which) ? e.which : 0));

    //If Shift
    if (characterCode == 16) {
        isDown = true;
    }
    //If CTRL
    if (characterCode == 17) {
        isDown = true;
    }

}
function checkEnter(e){ //e is event object passed from function invocation
    var characterCode; //literal character code will be stored in this variable
    e = (!e) ? window.event : e;

    characterCode = (e.charCode) ? e.charCode :
         ((e.keyCode) ? e.keyCode :
         ((e.which) ? e.which : 0));

    if(characterCode == 13 && (isDown == null || !isDown)){ //if generated character code is equal to ascii 13 (if enter key)
        send_chat_text(); //submit the form
        return false;
    } else {
        isDown = false;
        return true;
    }
}

function change_chat(chatid) {
    clearTimeout(timer_chats);
    //Add the chat just sent
    chat_content.innerHTML = '';
    //Set focus back to it
    chat_text.focus();
    chat_id = chatid;
    last_chat = 0;
    requestButtons();
    requestChats();
}

function loader() {
    users_content = xGetElementById("users");
    chat_text = xGetElementById("chat_text");
    chat_content = xGetElementById("chat_content");
    buttons = xGetElementById("chat_buttons");
    requestUsers();
    requestChats();
    chat_text.focus();
}

if (window.addEventListener) {
    window.addEventListener("load", loader, false);
} else if (window.attachEvent) {
    window.attachEvent("onload", loader);
}
Any ideas?


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
nathanr
Forum Contributor
Posts: 200
Joined: Wed Jun 07, 2006 5:46 pm

Post by nathanr »

I can't debug it all at this time.. but ehre's some pointers for you..

IE let's you atatch multiple events to the same "thing", even if they are identical.
therefore I'm thinking, everytime you set the the timout's your infact creating another one in IE..? also try adding in }else's ona ll your readFunctions
I'm sure this is what's causing the problem, not the settimeout specifically, but the multiple's of the same event
User avatar
Technocrat
Forum Contributor
Posts: 127
Joined: Thu Oct 20, 2005 7:01 pm

Post by Technocrat »

So your saying I should use clearTimeout() before remaking the timer?
User avatar
nathanr
Forum Contributor
Posts: 200
Joined: Wed Jun 07, 2006 5:46 pm

Post by nathanr »

entirely possible and it'll certainly do no harm :)

another thought is.. does the httprequest cause the load to fire again in ie.. maybe a detach event would ensure it's not this either
User avatar
Technocrat
Forum Contributor
Posts: 127
Joined: Thu Oct 20, 2005 7:01 pm

Post by Technocrat »

I have been trying to figure out where and what you meant by your else on the reads. Can you give me a specific example?

The httprequest should only be created once. How can I create a detached event?
User avatar
nathanr
Forum Contributor
Posts: 200
Joined: Wed Jun 07, 2006 5:46 pm

Post by nathanr »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


sorry I can be a bit vague, especially late at night (uk)

example: change >
[syntax="javascript"]function readChats() {
    // retrieve the server's response
    var response = xmlHttpGetChats.responseText;

    //Split the response
    var ret = new Array(2);
    ret = get_last_chat(response);
    response = ret[0];
    last_chat = ret[1];

    if (response.indexOf("ERRNO") >= 0 || response.indexOf("error:") >= 0 ) displayError('Sever Error '+response);
    if (response.length <= 1) {
        timer_chats = setTimeout("requestChats();", updateInterval);
        return;
    }

    chat_content.innerHTML = chat_content.innerHTML + response;
    chat_content.scrollTop = chat_content.scrollHeight;
    timer_chats = setTimeout("requestChats();", updateInterval);
} 
to ->

Code: Select all

function readChats() {
    // retrieve the server's response
    var response = xmlHttpGetChats.responseText;

    //Split the response
    var ret = new Array(2);
    ret = get_last_chat(response);
    response = ret[0];
    last_chat = ret[1];

    if (response.indexOf("ERRNO") >= 0 || response.indexOf("error:") >= 0 ) displayError('Sever Error '+response);
    if (response.length > 1) {
    chat_content.innerHTML = chat_content.innerHTML + response;
    chat_content.scrollTop = chat_content.scrollHeight;
    }
    timer_chats = setTimeout("requestChats();", updateInterval);
} 
didn't actually need an else I realised!

as for detach event:

Code: Select all

function loader() {
    window.detachEvent("onload", loader); //just to be safe
    users_content = xGetElementById("users");
    chat_text = xGetElementById("chat_text");
    chat_content = xGetElementById("chat_content");
    buttons = xGetElementById("chat_buttons");
    requestUsers();
    requestChats();
    chat_text.focus();
}

if (window.addEventListener) {
    window.addEventListener("load", loader, false);
} else if (window.attachEvent) {
    window.attachEvent("onload", loader);
}

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Technocrat
Forum Contributor
Posts: 127
Joined: Thu Oct 20, 2005 7:01 pm

Post by Technocrat »

Tried all your suggestions, and it's still a problem :? I got a few other suggestions on another site and still nothing. One person suggested it was a memory leak, but the memory usage in IE actually goes down over time with this code.

Here is the updated code:

Code: Select all

var updateInterval = 1000;
var users_content;
var chat_text;
var chat_content;
var buttons;
var xmlHttpGetUsers = createXmlHttpRequestObject();
var xmlHttpGetChats = createXmlHttpRequestObject();
var xmlHttpGetButtons = createXmlHttpRequestObject();
var xmlHttpGetSendMessage = createXmlHttpRequestObject();
var timer_chats;
var timer_users;
var isDown = false;
var newwindow = "";
var detach = false;

function createXmlHttpRequestObject() {
    // will store the reference to the XMLHttpRequest object
    var xmlHttp;
    // this should work for all browsers except IE6 and older
    try {
        // try to create XMLHttpRequest object
        xmlHttp = new XMLHttpRequest();
    } catch(e) {
        // assume IE6 or older
        var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                        "MSXML2.XMLHTTP.5.0",
                                        "MSXML2.XMLHTTP.4.0",
                                        "MSXML2.XMLHTTP.3.0",
                                        "MSXML2.XMLHTTP",
                                        "Microsoft.XMLHTTP");
        // try every prog id until one works
        for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
            try {
                // try to create XMLHttpRequest object
                xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
            } catch (e) {}
        }
    }
    // return the created object or display an error message
    if (!xmlHttp) {
        alert("Error creating the XMLHttpRequest object.");
    } else {
        return xmlHttp;
    }
}

/*=== Users ====*/
function requestUsers() {
    //Random number of IE
    var ran_number = Math.random()*5;
    //URL to go to
    var url = 'get_users.php?my='+my+'&type='+u_type+'&get_users=1&trash='+ran_number;

    if(xmlHttpGetUsers) {
        try {
            // don't start another server operation if such an operation
            //   is already in progress
            if (xmlHttpGetUsers.readyState == 4 || xmlHttpGetUsers.readyState == 0) {
                // call the server page to execute the server-side operation
                xmlHttpGetUsers.open("GET", url, true);
                xmlHttpGetUsers.onreadystatechange = handleReceivingUsers;
                xmlHttpGetUsers.send(null);
            } else {
                if (timer_users) {
                    clearTimeout(timer_users);
                    timer_users = null;
                }
                // we will check again for new users
                timer_users = setTimeout("requestUsers();", updateInterval);
            }
        } catch(e) {
            displayError(e.description);
        }
    }
}

function handleReceivingUsers() {
    // continue if the process is completed
    if (xmlHttpGetUsers.readyState == 4) {
        // continue only if HTTP status is "OK"
        if (xmlHttpGetUsers.status == 200) {
            try {
                // process the server's response
                readUsers();
            } catch(e) {
                // display the error message
                displayError(e.description);
            }
        } else {
            // display the error message
            displayError(xmlHttpGetUsers.statusText);
        }
    }
}

function readUsers() {
    // retrieve the server's response
    var response = xmlHttpGetUsers.responseText;
    //Clear the users
    users_content.innerHTML = '';

    //If there is an error
    if (response.indexOf("ERRNO") >= 0 || response.indexOf("error:") >= 0 )  displayError('Sever Error '+response);
    //If there is no data
    if (response.length > 2) {
        //Set the users HTML to the response
        users_content.innerHTML = response;
    }

    //Reset the timer
    if (timer_users) {
        clearTimeout(timer_users);
        timer_users = null;
    }
    timer_users = setTimeout("requestUsers();", updateInterval);
}

/*=== Chats ===*/
function requestChats() {
    //Random number of IE
    var ran_number = Math.random()*5;
    //URL to go to
    var url = 'chat.php?last_chat='+last_chat+'&sid='+chat_id+'&type='+u_type+'&my='+my+'&trash='+ran_number;

    if(xmlHttpGetChats) {
        try {
            // don't start another server operation if such an operation
            //   is already in progress
            if (xmlHttpGetChats.readyState == 4 || xmlHttpGetChats.readyState == 0) {
                // call the server page to execute the server-side operation
                xmlHttpGetChats.open("GET", url, true);
                xmlHttpGetChats.onreadystatechange = handleReceivingChats;
                xmlHttpGetChats.send(null);
            } else {
                if (timer_chats) {
                    clearTimeout(timer_chats);
                    timer_chats = null;
                }
                // we will check again for new messages
                timer_chats = setTimeout("requestChats();", updateInterval);
            }
        } catch(e) {
            displayError(e.description);
        }
    }
}

function handleReceivingChats() {
    // continue if the process is completed
    if (xmlHttpGetChats.readyState == 4) {
        // continue only if HTTP status is "OK"
        if (xmlHttpGetChats.status == 200) {
            try {
                // process the server's response
                readChats();
            } catch(e) {
                // display the error message
                displayError(e.description);
            }
        } else {
            // display the error message
            displayError(xmlHttpGetChats.statusText);
        }
    }
}

function readChats() {
    // retrieve the server's response
    var response = xmlHttpGetChats.responseText;

    //Split the response
    var ret = new Array(2);
    ret = get_last_chat(response);
    response = ret[0];
    last_chat = ret[1];

    if (response.indexOf("ERRNO") >= 0 || response.indexOf("error:") >= 0 )  displayError('Sever Error '+response);
    if (response.length > 2) {
        chat_content.innerHTML = chat_content.innerHTML + response;
        chat_content.scrollTop = chat_content.scrollHeight;
    }

    if (timer_chats) {
        clearTimeout(timer_chats);
        timer_chats = null;
    }
    timer_chats = setTimeout("requestChats();", updateInterval);
}

/*=== Send Chat ===*/
function send_chat_text() {
    //Random number of IE
    var ran_number = Math.random()*5;
    //URL to go to
    //We encode it in base 64 just to make sure that nothing gets lost in translation
    var url = 'chat.php?my='+my+'&type='+u_type+'&text='+ encode(chat_text.value) +'&chat_id=' +chat_id+'&trash='+ran_number;

    //Clear the text area
    chat_text.value ='';
    chat_text.focus();
    //Send the command
    if(xmlHttpGetSendMessage) {
        try {
            // don't start another server operation if such an operation
            //   is already in progress
            if (xmlHttpGetSendMessage.readyState == 4 || xmlHttpGetSendMessage.readyState == 0) {
                // call the server page to execute the server-side operation
                xmlHttpGetSendMessage.open("GET", url, true);
                xmlHttpGetSendMessage.send(null);
            }
        } catch(e) {
            displayError(e.description);
        }
    }
}

/*=== Buttons ===*/
function requestButtons() {
    var ran_number = Math.random()*10;
    var url = 'get_buttons.php?sid='+chat_id+'&my='+my+'&type='+u_type+'&trash='+ran_number;

    // only continue if xmlHttpGetMessages isn't void
    if(xmlHttpGetButtons) {
        try {
            // don't start another server operation if such an operation
            //   is already in progress
            if (xmlHttpGetButtons.readyState == 4 || xmlHttpGetButtons.readyState == 0) {
                // call the server page to execute the server-side operation
                xmlHttpGetButtons.open("GET", url, true);
                xmlHttpGetButtons.onreadystatechange = handleReceivingButtons;
                xmlHttpGetButtons.send(null);
            }
        } catch(e) {
            displayError(e.description);
        }
    }
}

function handleReceivingButtons() {
    // continue if the process is completed
    if (xmlHttpGetButtons.readyState == 4) {
        // continue only if HTTP status is "OK"
        if (xmlHttpGetButtons.status == 200) {
            try {
                // process the server's response
                readButtons();
            } catch(e) {
                // display the error message
                displayError(e.description);
            }
        } else {
            // display the error message
            displayError(xmlHttpGetButtons.statusText);
        }
    }
}

function readButtons() {
    // retrieve the server's response
    var response = xmlHttpGetButtons.responseText;

    if (response.indexOf("ERRNO") >= 0 || response.indexOf("error:") >= 0 )  displayError('Sever Error '+response);
    if (response.length == 0) {
        return;
    }

    buttons.innerHTML = response;
}

/*=== Other Functions ===*/

// function that displays an error message
function displayError(message) {
    alert("Error accessing the server! "+ "\r\n" + message);
}

function get_last_chat(Request) {
    var ret = new Array(2);
    loc = Request.indexOf('<last_chat>');
    loc2 = Request.indexOf('</last_chat>');
    if ((loc-1) <= 0) {
        ret[0] = '';
    } else {
        ret[0] = Request.substring(0, loc-1);
    }
    ret[1] = Request.substring(loc+11, loc2);
    return ret;
}

function keydown(e) {
    var characterCode; //literal character code will be stored in this variable
    e = (!e) ? window.event : e;

    characterCode = (e.charCode) ? e.charCode :
         ((e.keyCode) ? e.keyCode :
         ((e.which) ? e.which : 0));

    //If Shift
    if (characterCode == 16) {
        isDown = true;
    }
}

function checkEnter(e){ //e is event object passed from function invocation
    var characterCode; //literal character code will be stored in this variable
    e = (!e) ? window.event : e;

    characterCode = (e.charCode) ? e.charCode :
         ((e.keyCode) ? e.keyCode :
         ((e.which) ? e.which : 0));

    if(characterCode == 13 && (isDown == null || !isDown)){ //if generated character code is equal to ascii 13 (if enter key)
        send_chat_text(); //submit the form
        return false;
    } else {
        isDown = false;
        return true;
    }
}

function change_chat(chatid) {
    clearTimeout(timer_chats);
    //Add the chat just sent
    chat_content.innerHTML = '';
    //Set focus back to it
    chat_text.focus();
    chat_id = chatid;
    last_chat = 0;
    requestButtons();
    requestChats();
}

function popitup(url) {
	window.open(url, "", "menubar=1,resizable=1,width=770,height=380");
	return false;
}

function popitupIE(url) {
	window.open(url);
	return false;
}

function loader() {
    if (detach) window.detachEvent("onload", loader); //just to be safe
    users_content = xGetElementById("users");
    chat_text = xGetElementById("chat_text");
    chat_content = xGetElementById("chat_content");
    buttons = xGetElementById("chat_buttons");
    requestUsers();
    requestChats();
    chat_text.focus();
}


function unloader() {
    if (timer_chats) {
        clearTimeout(timer_chats);
        timer_chats = null;
    }
    if (timer_users) {
        clearTimeout(timer_users);
        timer_users = null;
    }
    xmlHttpGetUsers = null;
    xmlHttpGetChats = null;
    xmlHttpGetButtons = null;
    xmlHttpGetSendMessage = null;
    if (detach) window.detachEvent("onunload", unloader); //just to be safe
}

if (window.addEventListener) {
    window.addEventListener("load", loader, false);
    window.addEventListener("unload", unloader, false);
} else if (window.attachEvent) {
    detach = true;
    window.attachEvent("onload", loader);
    window.attachEvent("onunload", unloader);
}
Post Reply