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

192
Vistas
How can I handle dynamic content in external javascript file?

I have a website in several languages and it happens that there are some visitors who for some reason are viewing a page in a different language than that of their browser settings. Therefore, if their browser language is one of those the site is translated into, I suggest they switch to their preferred language. I do this with a div containing a message at the top of the page.

According to your settings, we suggest you to view the content of this page in the following language: {language link}.
{Denied option with link}

The message is shown in the current language (I have all the translations of course), while {language link} is taken from the user's settings. The javascript code is generated Serverside with PHP and managed by Javascript in the HTML

<script> 
// instructions loaded, matching user conditions...
</script>

Is there any way to manage it in an external js file? How to do? Obviously, I'm not interested in preparing n*n combinations of files and uploading the one that matches the visitor's situation.

How to do? Thank you!

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

0

You can probably write particular JavaScript server side that assigns data to a global variable, in addition to your external script.

In the server-rendered page, it'd look something like:

<script>
  var userSettingsLanguageLink = '{language link}';
</script>

And then in your external script, something like:

  if (userSettingsLanguageLink !== getBrowserLanguage())
  //...
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