0

for a project I need to check the Response Code of a dynamically added JS into DOM. So Code looks basically like this one:

var newScript = document.createElement("script");
newScript.src = "http://www.example.com/dynamic-XXX.js";
target.appendChild(newScript);

The XXX will change and I am loading the File from Google Cloud Storage. So if I have a 200, everything is fine. But I need to check if I have 201 Status Code.

Any Ideas how to solve this in a nice way ?

sluga.io
  • 25
  • 1
  • You should be able to set an onload and an onerror attribute (or add the equivalent with addEventHandler). See https://www.w3schools.com/jsref/event_onload.asp and https://www.w3schools.com/jsref/event_onerror.asp – user2740650 Feb 26 '22 at 21:58
  • Please take a look at https://stackoverflow.com/questions/9521298/verify-external-script-is-loaded I think it can helps you. – Umamad Feb 26 '22 at 21:59

0 Answers0