Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

javascript - changing text properties as part of html script

I want to build a simple http server which receives list of text strings and sends simple dynamic html page which presents them in loop (similar to RSS) It works fine but now I want to control text properties How can I change text properties e.g. change background to transparent, text size and font? The page is built using python HTTPserver module It is sent single simple html page as a respond to GET request and I am not sure how I can embed css or other tricks in the script

Below python function receives string which contains list of strings (text) separated by commas, embeds it as array inside of html script (replaces TEXT with text) and sends it as part of html body in the respond

def write_response(self, text):
    print(content)
    self.send_response(200)
    self.send_header('Content-type', 'text/html; charset=utf-8')
    self.end_headers()

    f = open('html.txt', "r")
    html = f.read()
    body = html.replace('TEXT', text)
    print(body)
    self.wfile.write(body.encode(encoding='utf-8'))

html.txt file

   <script>
        var example = [TEXT];

        textSequence(0);
        function textSequence(i) {

            if (example.length > i) {
                setTimeout(function() {
                    document.getElementById("sequence").innerHTML = example[i];
                    textSequence(++i);
                }, 1000); // 1 second (in milliseconds)

            } else if (example.length == i) { // Loop
                textSequence(0);
            }

        }
    </script>

   <div id="sequence"></div>
question from:https://stackoverflow.com/questions/65643206/changing-text-properties-as-part-of-html-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...