Search
 
SCRIPT & CODE EXAMPLE
 

HTML

html chat box

<h1>Chat-box (With HTML and JAVASCRIPT)</h1>
<title>User chat</title>
<div><input id=input placeholder="Press Enter to Send" /></div><br><br>
Chat Output
<div id=box></div>
<script src=https://cdn.pubnub.com/sdk/javascript/pubnub.4.28.2.min.js></script>
<script> (function() {
        var pubnub = new PubNub({
            publishKey: 'demo',
            subscribeKey: 'demo'
        });
        function $(id) {
            return document.getElementById(id);
        }
        var box = $('box'),
            input = $('input'),
            channel = '10chat-demo';
        pubnub.addListener({
            message: function(obj) {
                box.innerHTML = ('' + obj.message).replace(/[<>]/g, '') + '<br>' + box.innerHTML
            }
        });
        pubnub.subscribe({
            channels: [channel]
        });
        input.addEventListener('keyup', function(e) {
            if ((e.keyCode || e.charCode) === 13) {
                pubnub.publish({
                    channel: channel,
                    message: input.value,
                    x: (input.value = '')
                });
            }
        });
    })();
</script>
Comment

PREVIOUS NEXT
Code Example
Html :: how to make body element in html 
Html :: dashboard box in adminlte 
Html :: html disclaimer text 
Html :: emoji icon html 
Html :: control icon size html 
Html :: ms crm aadhar number validation javascript 
Html :: electron js linux dependency 
Html :: zoneofdevelopment 
Html :: fab model 
Html :: buy onion website 
Html :: thtrhthth 
Html :: app script send data back to html 
Html :: modpagespeed off htaccess 
Html :: table align center not working in github 
Html :: wp bakery add shortcode backend 
Html :: pass parameter 2 html button 
Html :: webpack Hot replace module unsafe-inline 
Html :: space animation html 
Html :: how to check *ngIf with ENUMs in componenet.html 
Html :: statamic regex replace 
Html :: form table selection 
Html :: web development html chapter 1 
Html :: how to create search bar in html with aria-label 
Html :: visa card 
Html :: embed using shortcode 
Html :: sticky footer css grids 
Html :: how to hide youtube watermark from embedded video :2021 
Html :: is html dead 
Html :: html. strong 
Html :: html iframe only show part of page 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =