Simple implementation of screen flushing in chat rooms

Source: Internet
Author: User

Simple implementation of screen flushing in chat rooms

In the chat room, if we want to achieve screen flushing, it is actually very simple, because we can do this through front-end js.


First, let's talk about the principle. It uses javascript to simulate text input and click the submit button. To achieve this, we need to debug the browser first, such as firebug of firefox, or the built-in debugging tool, or the chrome console, ie + 8 F12 developer tool.


The following is a simple example:


First, review the elements, find the id of the input box, such as: id = "postTex" t, and then find the submitted id or css, such as class = "btn_submit ",

Here we can enter a large segment, which can be copied to str for a long time. You can also copy the text in the source code from other websites, then I use the regular expression to remove the html Tag.

Some Chat rooms have the speed of text input, so I use the setInterval of javascript to set a delay time to send messages, so that the screen can be automatically refreshed.

The Code is as follows:


var i = 0;var j = 100;var str = "this is the test string will be show in input text.";str = str.replace(/<[^>].*?>/g,"");
function output(i){var input = str.substr(i,10);jQuery("#postText").val(input);jQuery(".btn_submit").click(); }var interval = setInterval(function(){output(i);i = i +10;if(i>1000){clearInterval(interval);console.log('ok');}},6000);


Here we hope that we will apply what we have learned to practical applications, so that we can have a deeper understanding of the knowledge and enjoy it.


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.