Foros del Web » Programando para Internet » Javascript »

Pequeña duda con document.write

Estas en el tema de Pequeña duda con document.write en el foro de Javascript en Foros del Web. Buenas, tengo una gran duda, yo si hago un: Código: <script> var win; win = window.open('', 'POPUP' , 'resizable=no, scrollbars=no, status=yes'); var x = 425; ...
  #1 (permalink)  
Antiguo 14/05/2004, 04:55
Avatar de epplestun  
Fecha de Ingreso: octubre-2001
Mensajes: 1.621
Antigüedad: 22 años, 6 meses
Puntos: 5
Pequeña duda con document.write

Buenas, tengo una gran duda, yo si hago un:

Código:
<script>
var win;
win = window.open('', 'POPUP' , 'resizable=no, scrollbars=no, status=yes');
var x = 425;
var y = 390;
		
win.resizeTo(x, y);
win.moveTo((screen.width - x)/2, (screen.height - y)/2);

win.document.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
win.document.write("<html>");
win.document.write("<head>");
win.document.write("<meta content=\"text/html; charset=iso-8859-1\" http-equiv=\"content-type\">");
win.document.write("<title>Insertar imagen</title>");
win.document.write("</head>");
win.document.write("<body topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\" marginheight=\"0\" marginwidth=\"0\"");

win.document.write("<iframe id=\"p\" src=\"x.html\" onload=\"show();\"></iframe>");
win.document.write("<script>");
win.document.write("function show() {");
win.document.write("	alert(document.getElementById('p').contentWindow.document.body.innerHTML);");
win.document.write("	return false;");
win.document.write("}");
win.document.write("<\/script>");
win.document.write("</body>");
win.document.write("</html>");
win.document.close();
</script>
Eso no funciona, pero si hago un:

Código:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>
<iframe id="p" src="x.html" onload="show();"></iframe>
<script>
function show() {
	alert(document.getElementById('p').contentWindow.document.body.innerHTML);
	return false;
}
</script>

</body>
</html>
Funciona perfectamente .... alguien sabe por que?¿
Y por que tambien si una etiqueta como <body></body> ... no te da error por uqe si lo da <script></script>?

Muchas gracias!!
__________________
Usuario registrado de Linux #288725
  #2 (permalink)  
Antiguo 14/05/2004, 05:43
Avatar de KarlanKas
Moderador extraterrestre
 
Fecha de Ingreso: diciembre-2001
Ubicación: Madrid
Mensajes: 6.987
Antigüedad: 22 años, 4 meses
Puntos: 61
Tenías un par de fallitos (no habías cerrado el body y la función debe estar antes del elemento que la llama). Prueba con esto:
Código PHP:
<script>
var 
win;
win window.open('''POPUP' 'resizable=no, scrollbars=no, status=yes');
var 
425;
var 
390;
        
win.resizeTo(xy);
win.moveTo((screen.width x)/2, (screen.height y)/2);

win.document.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
win.document.write("<html>");
win.document.write("<head>");
win.document.write("<meta content=\"text/html; charset=iso-8859-1\" http-equiv=\"content-type\">");
win.document.write("<title>Insertar imagen</title>");
win.document.write("</head>");
win.document.write("<body topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\" marginheight=\"0\" marginwidth=\"0\">");
win.document.write("<scr"+"ipt>");
win.document.write("function show() {");
win.document.write("    alert(document.getElementById('p').contentWindow.document.body.innerHTML);");
win.document.write("    return false;");
win.document.write("}");
win.document.write("<\/scr"+"ipt>");
win.document.write("<iframe id=\"p\" src=\"x.html\" onload=\"show();\"></iframe>");

win.document.write("</body>");
win.document.write("</html>");
win.document.close();
</script> 
__________________
Cómo escribir

No hay pregunta tonta, sino tonto que quiere seguir en la ignorancia.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:35.