Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!