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

62
Views
¿Puede agregar declaraciones if en caso de que un elemento src no aparezca con un estado de devolución de 404?

Estoy tratando de usar dos hosts de secuencias de comandos en caso de que uno no se muestre, pero mi declaración de captura no parece estar detectando errores de estado 404 cuando arruino la URL a propósito. Aquí está el código:

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://cdn.jsdelivr.net/npm/p5@1.0.0/lib/p5.js"></script> <script onerror="error()" ></script> <script src="blockman.js"></script> <script src="https://craigapphostl.w3spaces.com/scripts.js"></script> <title>Document</title> <button onclick="f()">Test</button> </head> <body> </body> <script> function error(){ //added l's on the end to both script host links alert("some thing hs went wrong trying back up host") } try{ var t=document.createElement("script") t.setAttribute("src","https://vdkhiyrhibxzmpiophft.w3spaces.com/scripts.js") document.body.appendChild(t); } catch(e){ alert(e) } </script> </html>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Este tipo de error no se puede detectar con try...catch . En su lugar, escuche el evento de error .

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://cdn.jsdelivr.net/npm/p5@1.0.0/lib/p5.js"></script> <script onerror="error()"></script> <script src="blockman.js"></script> <script src="https://craigapphostl.w3spaces.com/scripts.js"></script> <title>Document</title> <button onclick="f()">Test</button> </head> <body> </body> <script> function error() { //added l's on the end to both script host links alert("some thing hs went wrong trying back up host") } var t = document.createElement("script"); // Alerts "Error loading script" if there was an error t.onerror = err => alert("Error loading script"); t.setAttribute("src", "https://vdkhiyrhibxzmpiophft.w3spaces.com/scripts.js"); document.body.appendChild(t); </script> </html>

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!