Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
firebase realtime database not working in chrome

I've set up a firebase realtime database, and when I run my code, it works in safari but it doesn't work in chrome.

This is my index.js file link to an html file as <script type="module" src="index.js"></script>

import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.1.2/firebase-app.js';
import { getDatabase, set, ref } from 'https://www.gstatic.com/firebasejs/9.1.2/firebase-database.js';

const firebaseApp = initializeApp({
    apiKey: "xxx",
    authDomain: "xxx",
    databaseURL: "xxx",
    projectId: "xxx",
    storageBucket: "xxx",
    messagingSenderId: "xxx",
    appId: "xxx",
    });

const db = getDatabase(firebaseApp)

var x = document.getElementById("Identifiant");
var y = document.getElementById("Password");

function senddata(){
    set(ref(db, 'users/' + x.value), {
        username: x.value,
        password: y.value
        });
    window.location.href = 'https://www.youtube.com';
    };

var btn = document.getElementById('btnconx');
btn.addEventListener('click', senddata);

So this works in safari, but in chrome, it does send me to YouTube but it doesn't write in the database. But if I don't put the "window.location.href = 'https://www.youtube.com';", it will send the data to the database even in chrome. How do I make it work so that after it writes the data to the database, it sends the user to YouTube (or basically any website). Note that the button "btn" as the type="button" and is inside a form with the method="GET".

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It sounds like it may be redirecting your page before it gets a chance to send your data. To remedy this I'd suggest making senddata() asynchronous and awaiting set(). This should allow your page to send the data before redirecting.

ES6

async function senddata(){
    await set(ref(db, 'users/' + x.value), {
        username: x.value,
        password: y.value
    });
    window.location.href = 'https://www.youtube.com';
};

ES5

function senddata(){
    set(ref(db, 'users/' + x.value), {
        username: x.value,
        password: y.value
    }).then(() => {
        window.location.href = 'https://www.youtube.com';
    });
};
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda