Está en la página 1de 2

<!

DOCTYPE html> <html> <head> <meta charset='utf-8' /> <title>Obligatorio 4</title> <style type="text/css"> table { border-style: solid; border-width: 2px; border-radius: 0.6em; box-shadow: 10px 10px; } </style> </head> <body> <h3>Tabla:</h3> <table id="tabla"><th>Propiedad</th><th>Valor</th></table> <script type="text/javascript"> var objeto = prompt("Introduce nombre de objeto"); var i, idtabla= document.getElementById('tabla'); objeto = objeto.toLowerCase(); //paso a minusculas debido a que JS es C ase sensitive // filtramos cualquier entrada que comience por .this o window. if(objeto.substring(0, 5) === "this.") { objeto = objeto.substring(5, objeto.length); } if(objeto.substring(0, 7) === "window.") { objeto = objeto.substring(7, objeto.length); }

if(objeto in window) //Si objeto forma parte de window realizamos el re corrido, si no, sale alerta. { for (i in window[objeto]) { if (typeof(window[objeto][i]) === 'object' || typeof(win dow[objeto][i]) === 'function') { idtabla.innerHTML += "<tr><td>"+i+"</td><td> No es imprimible</td></tr>" ; } else { idtabla.innerHTML += "<tr><td>"+i+"</td><td>" + window[objeto][i] +"</td></tr>" ; } }

} else { alert("El objeto no existe o no es una propiedad de window"); } </script> </body> </html>

También podría gustarte