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

chatbot html


<body>
 
    <mybot></mybot>

  </div>

  <script src="https://ajax.********************ery.min.js"></script>
  <script src="assets/js/script.js"></script>
</body>
Comment

PREVIOUS NEXT
Code Example
Html :: embed link in markdown 
Html :: disabled attribute is not working in html 
Html :: how to preview pdf in html 
Html :: box search bootstrap 
Html :: free html signature template 
Html :: javascript window.print 
Html :: bootstrap modal remove gray background 
Html :: markdown table cell multiple lines 
Html :: get image from google drive 
Html :: how to include a dash in html 
Html :: html sample code 
Html :: call javascript function from a tag 
Html :: link open in new tab html 
Html :: input type button 
Html :: html a 
Html :: bootstrap 5 accordion 
Html :: iframe youtube playlist not working html 
Html :: html video autosize 
Html :: mailto in html 
Html :: bootstrap error message 
Html :: svg as button 
Html :: how to write a text inside a div 
Html :: slider video play 
Html :: input type text inside select option 
Html :: object htmldivelement to string 
Html :: select option 
Html :: year dropdown in html 
Html :: html style attribute 
Html :: twig array keys and values 
Html :: allow multiple select on radio button in html 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =