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

html chatbot

<!DOCTYPE html>
<html>
<body>
<style>
button {
  background-color: dodgerblue;
}
p {
  text-align: center;
}
</style>

<p><button onclick="myFunction()">Click here to wake me up</button></p>

<p id="demo"></p>

<script>
function myFunction() {
  var text;
  var ms = prompt("Ask me anything.");
  switch(ms) {
    case "hello":
      text = "HI, What do you want to ask me?";
      break;
    case "how are you":
      text = "I am fine. Hope you are fine too.";
      break;
    case "hi":
      text = "Yes. What do you want to ask?";
      break;
    case "hey":
      text = "Yes. What do you want to ask?";
      break;      
    case "yes":
      text = "Okay. So what do you want to ask?";
      break;
    case "search":
      text = '<form action="https://www.google.com/search" target="_blank"><input name="q" size="50" placeholder="type your search term and click enter"></form>';
      break;
    case "functions":
      text = "I can help you to find answers to your questions, I can give the weather report , I can show you the current time";
      break;      
    case "weather":
      text = '<a href="https://www.accuweather.com/en/us/google/94043/weather-forecast/74907_poi" target="_blank">Weather report</a>';
      break;     
    case "time":
      text = new Date().toLocaleTimeString();
      break;
    default:
      text = "I didn't understand that";
  }
  document.getElementById("demo").innerHTML = text;
}
</script><hr>

<p>TYPE hello, how are you, hi, hey, yes, search, functions, weather, time etc.</p>

</body>
</html>
Comment

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

html chatbot

<!DOCTYPE html>
<html>
<body>
<style>
button {
  background-color: dodgerblue;
}
p {
  text-align: center;
}
</style>

<p><button onclick="myFunction()">Click here to wake me up</button></p>

<p id="demo"></p>

<script>
function myFunction() {
  var text;
  var ms = prompt("Ask me anything.");
  switch(ms) {
    case "hello":
      text = "HI, What do you want to ask me?";
      break;
    case "how are you":
      text = "I am fine. Hope you are fine too.";
      break;
    case "hi":
      text = "Yes. What do you want to ask?";
      break;
    case "hey":
      text = "Yes. What do you want to ask?";
      break;      
    case "yes":
      text = "Okay. So what do you want to ask?";
      break;
    case "search":
      text = '<form action="https://www.google.com/search" target="_blank"><input name="q" size="50" placeholder="type your search term and click enter"></form>';
      break;
    case "functions":
      text = "I can help you to find answers to your questions, I can give the weather report , I can show you the current time";
      break;      
    case "weather":
      text = '<a href="https://www.accuweather.com/en/us/google/94043/weather-forecast/74907_poi" target="_blank">Weather report</a>';
      break;     
    case "time":
      text = new Date().toLocaleTimeString();
      break;
    default:
      text = "I didn't understand that";
  }
  document.getElementById("demo").innerHTML = text;
}
</script><hr>

<p>TYPE hello, how are you, hi, hey, yes, search, functions, weather, time etc.</p>

</body>
</html>
Comment

PREVIOUS NEXT
Code Example
Html :: how do you play audio files on html 
Html :: html print today date 
Html :: how to contrast img in html 
Html :: is titanfall 2 good 
Html :: input width autosize 
Html :: hide html element show on print bootstrap 4.6 
Html :: Send a SMS Text From A Link - the new code 
Html :: open link in a new tab 
Html :: embed tag youtube 
Html :: a tag open new tab 
Html :: cdn material design icons 
Html :: How to Remove the Arrow of Input Type= "Number" in Firefox Browser 
Html :: html preload images 
Html :: tailwind css checkbox 
Html :: fa fa dropdown icon 
Html :: django template variable remove all spaces 
Html :: html phone call 
Html :: what is seizure disorder 
Html :: require in html 
Html :: open new tab anhor tag 
Html :: stop website from letting you overscroll 
Html :: dart remove html tags 
Html :: best html coding software 
Html :: angular input onchange 
Html :: html.erb conditionally add class 
Html :: form action without redirect 
Html :: bootstrap change navbar font size 
Html :: html span title tooltip 
Html :: html make a table with two top headers 
Html :: bootstrap 5 input group 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =