“kotak obrolan html” Kode Jawaban

kotak obrolan html

<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>
Thomas coder

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>
Thomas coder

Jawaban yang mirip dengan “kotak obrolan html”

Pertanyaan yang mirip dengan “kotak obrolan html”

Lebih banyak jawaban terkait untuk “kotak obrolan html” di HTML

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya