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

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

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 Report

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