Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
I create a messaging app using firebase but there is a very confusing error

I created a simple messaging website but faced a difficult problem: A and B each have two chat groups as shown in the picture, when B switches to B&D group and then A messages in A&B but that message pops up in the B&D group??!!
This is my Javascript code:

const app = initializeApp(firebaseConfig);
const database = getDatabase();

var message = document.getElementById("input"); //input
var btn = document.getElementById("send"); //send button

var order = document.getElementsByClassName("chat-head"); //class name of chat group
var room_name = "a&b"; //A&B is default group when open web (example)

function send(){
    push(ref(database, room_name),{
        Message: message.value
    });
    message.value = "";
}
function receive(){
    onValue(ref(database, room_name), snapshot => {
        snapshot.forEach(element => {
            //print name of chat group and messages in it
            console.log(room_name, element.val())
        });
    });
}
function chatHead(){
    //set color the chat group which I choose is red
    order[0].style.backgroundColor = "red";
    for(let i = 0; i < order.length; i++) {
        order[i].addEventListener("click", () => {
            order[i].style.backgroundColor = "red";
            for(let j = 0; j < order.length; j++){
                if(j != i){
                    order[j].style.backgroundColor = "white"; // and others is white
                }
            }
            room_name = order[i].id;
            receive();
        });
    }
}
chatHead();
window.onload = receive();
btn.addEventListener("click", send);

picture1

picture2

picture3

messages

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda