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

132
Visualizações
How to target & replace the name of a property from a different document in JavaScript?

Im wanting to replace/translate text on a webpage. This is for some online software where I only have access to a custom code section.

Ive managed to translate some words, but my script doesn't have an affect on some others which are populated from a different file called storeSettings.js.

How can I edit my current translation script to translate the words I need in storeSettings.js ?

This is my current translation code to replace the word 'State' with 'County':

window.onload = function() {const replaceOnDocument = (pattern, string, {target = document.body} = {}) => {
  [
    target,
    ...target.querySelectorAll("*:not(script):not(noscript):not(style)")
  ].forEach(({childNodes: [...nodes]}) => nodes
    .filter(({nodeType}) => nodeType === document.TEXT_NODE)
    .forEach((textNode) => textNode.textContent = textNode.textContent.replace(pattern, string)));
};

replaceOnDocument(/State/g, "County");
                        };

And this is the contents of storeSettings.js



 var fillGeneralSettings = function () {
      mergeUnique(settings.general, {
        state: '',
      }, true);

{
          property: 'state',
          field: self.container.find('[name="state"]')
        }

Say I want to replace 'State' with 'County' (cosmetically). Instead of target = document.body in my translation script what should I replace it with to access the content of storeSettings.js?

Thank you! :)

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