Programming Solution Chat Room refresh problem (Source: Sadie Net-China computer newspaper)

Source: Internet
Author: User
Tags client
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.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.