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

183
Views
resultado de depuración de javascript de área de texto para el párrafo innerHTML "indefinido"

Estoy haciendo un editor de código, casi todo funciona, escribo el texto en el texarea y presiono un botón para cargar una función, y el resultado del código aparece en la consola del navegador web, estoy tratando de hacer como "document. getElementById('salida').innerhtml = window.eval(txtarea.value);" pero no parece funcionar.

 function DebugInp(){ var txtarea = document.getElementById('input'); document.getElementById('output').innerHTML = window.eval(txtarea.value);//output = paragraph in html. }; /** *My problem is that the innerHTML is showing undefined, but when I'm getting to console, *it appears the result. *I'm thinking of maybe getting all of the outputs of the console, but IDK how to do it *Kind of like: document.getElementById('output').innerHTML = console.logs? *I am still searching but any help would be nice. */

¡gracias de antemano! PD: soy mejor en desarrollo frontend, tratando de entender más el backend, así que no odien 🙂 por favor.

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

0

Lo que estás haciendo es muy inseguro y hay muchas mejores maneras de hacerlo. Sin embargo, debe restringir el contexto de su código de entrada. La simple evaluación de todo el código no le dará los registros de la consola. Debe exponer una API para que el código envíe la salida.

Ejemplo mínimo:

 var txtarea = document.getElementById('input'); document.getElementById('output').innerHTML = window.eval(` const console = { log(...args) { document.getElementById('output').innerText += '\n' + args.join(' '); } }; ${txtarea.value} `);
about 4 years ago · Juan Pablo Isaza Report

0

¡¡¡OH!!! lo hice chicos! Simplemente cree una nueva función estándar para console.log para que almacene todos los registros. Encontré la respuesta aquí: https://stackoverflow.com/a/19846113/16260964

 console.stdlog = console.log.bind(console); console.logs = []; console.log = function(){ console.logs.push(Array.from(arguments)); console.stdlog.apply(console, arguments); } var txtarea = document.getElementById('input'); window.eval(txtarea.value); document.getElementById('output').innerHTML = console.logs;

¡GG! ¡Que tengan un gran día a todos! 🎊🎉🥳

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!