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

211
Vistas
JavaScript object containing multiple Base64 image codes

Project:

Loading screen with Base64 image in Playcanvas (WebGL)

What I try to do:

Change the image when the Website is loaded with other language (index.html?language=xy)

What I already have:

I get the default image in my WebGL loading javascript.

 var logo = document.createElement('img');
    logo.src = 'here is my base64 code';
    splash.appendChild(logo);
    logo.onload = function() {
    splash.style.display = 'block';
    };

I thought it would be the best option to list all languages in an object, and invoke the object with the language that is currently selected.

Why I can't figure it out myself:

As I just started creating javascript projects, I need to lookup many thing, but when I search up my issue I get stuff like this Base64 encode a javascript object

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

0

  1. Define all the images in an object

    const images = {
      'us': 'data:image/jpeg;base64,...',
      'nl': 'data:image/jpeg;base64,...',
      'fallback': 'data:image/jpeg;base64,...'
    }
    
  2. Parse the query paramters, use a fallback if not given

    const urlSearchParams = new URLSearchParams(window.location.search);
    const params = Object.fromEntries(urlSearchParams.entries());
    
    let lanuageKey = params['language'];
    if (!images[lanuageKey]) {
        lanuageKey = 'fallback';
    }
    
  3. Add the image with desired base64

    var logo = document.createElement('img');
    logo.src = images[lanuageKey];
    document.body.appendChild(logo);
    

Putting this all together, will give something like the following snippet:
Note 1: Stack Snippets can't read the query params, so you'll need to try this locally
Note 2: Due to the 30k max chars, I had to remove the base64's

const images = {
    'us': 'data:image/jpeg;base64...',
    'nl': 'data:image/jpeg;base64...',
    'fallback': 'data:image/jpeg;base64...'
}

const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());

let lanuageKey = params['language'];
if (!images[lanuageKey]) {
    lanuageKey = 'fallback';
}

var logo = document.createElement('img');
logo.src = images[lanuageKey];
document.body.appendChild(logo);

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