Programming | solving | chat room Refresh | Problem Programming Solution Chat Room refresh problem
When writing a chat room program, we usually have two ways to upload the server data to the browser. One is when there is information on the server side, push the information to the client, this way makes the load of the server heavier, the other is in the client with the Refresh command, most of the chat room in this way, so that we see the screen in the browser is constantly refreshing, very affected browsing, This is even more serious when the internet is slow.
Is there a good way to solve the problem? The answer is yes. The following author introduces a way to use JavaScript to solve this problem. Although this method is not the best, but simple, interested readers may wish to try.
First, we divide the page into three frames. The above frame is main.htm, used to display the content of the chat, the following frame is bottom.htm, used to enter the chat content. Then, add a hidden frame list.asp, the role of this frame is to make the input information can be displayed in the main.htm frame. The following is the source program for the chat room.
The frame.htm source program is as follows:
〈html〉
〈head〉
〈title〉asp Cool Chat Room 〈/title〉
〈meta http-equiv= "Content-type" content= "text/html; arset=gb2312 "
〈/head〉
〈frameset rows= "0,403,92" cols= "*"
〈frame src= "list.asp" name= "list"
〈frame src= "main.htm" name= "Main1"
〈frame src= "Bottom.htm"
〈/frameset〉
〈noframes〉
〈body bgcolor= "#ffffff"
〈/body〉〈/noframes〉
〈/html〉
The main.htm source program is as follows:
〈html〉
〈head〉
〈title〉 Chat content display area 〈/title〉
〈meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "
〈/head〉
〈body bgcolor= "#ffffff"
〈/body〉
〈/html〉
The bottom.htm source program is as follows:
〈html〉
〈head〉
〈title〉 Chat Content Entry Area 〈/title〉
〈meta http-equiv= "Content-type" content= "text/html;charset=gb2312" 〉〈/head〉
〈body bgcolor= "#ffffff"
〈form name= "Form1" method= "Post" action= "list.asp" target= "list"
〈div align= "Center"
〈input type= "text" name= "comment"
〈input type= "Submit" name= "submit" value= "Write and read"
〈/div〉
〈/form〉
〈/body〉
〈/html〉
The list.asp source program is as follows:
〈script language= "JavaScript"
function Scrollon () {
Top.main1.scroll (0, 65000);
}
Top.main1.document.write (' 〈=request (comment) ')
Top.main1.document.ite ' 〈br〉 ')
〈/script〉
In the above method, when entering the chat content, in the chat room display area, the user can see the content to write down in a row, but does not appear the screen continuously refreshes the situation. As long as you change the list.asp, you can get the chat from the database or from the Application object. It's just possible that list.asp needs to be refreshed, but for people chatting in a chat room, the chat content is moving down one line, and they don't feel like the screen is refreshing.