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

136
Visualizações
Getting currentScript is returning typeError

I'm trying to get a custom attribute that I put on my script tag:

<script type="text/javascript" src="https://.../mysource.js" customdata="some_value"></script>

I'm using the following code so it will work on IE:

document.currentScript =
  document.currentScript ||
  (function () {
    const field = document.getElementsByTagName('script');
    return field[field.length - 1];
  })();

// document.currentScript.getAttribute('customdata');

But then I'm receving the following error when I try to set a new value on document.currentScript.

Uncaught TypeError: Cannot set property currentScript of # < Document > which has only a getter

I only solve this when I'm using document.currentScript directly, but then I can't use on older browsers.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I created another variable to hold the value from document and then it worked and no errors is shown.

about 4 years ago · Juan Pablo Isaza Relatório

0

If document.currentScript exists, it's a read-only property. So only try to set it if it doesn't exist.

if (!document.currentScript) {
  document.currentScript = (function() {
    const field = document.getElementsByTagName('script');
    return field[field.length - 1];
  })();
}
about 4 years ago · Juan Pablo Isaza Relatório
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