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

135
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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