Writing in a secondary window

0

What I want to do is a document.write () in the main window, and another in the secondary window that opens. I know it will be silly but I've been a while now and I'm not capable.

What I am doing is something like that, but it is clear that it does not work:

<doctype HTML>
<html>
	<head>
		<meta charset='utf-8'>
		<title></title>
		<style>
		</style>
		<script type="text/javascript">
			
			var subventana=window.open("index.html", "", "height=600, width=800");
			//sub_ventana.moveTo(0,0);
			subventana.resizeTo(800,600);
			document.write("<h1>Hola1</h1><br />");

			function realizar(){

				subventana.document.write("<h3>Hola2</h3><br />");

			}

			realizar();

		</script>
	</head>
	<body>
	</body>
</html>
    
asked by Jopimar 02.12.2016 в 15:39
source

2 answers

0

Surely the browser that you are using does not show you the result because the label of your html was wrong or if it is not because it is blocking you because of the popups theme. See if it blocks you.

<!DOCTYPE html>
<html lang="es">
    <head>
        <meta charset='utf-8'>
        <title></title>
        <style>
        </style>
        <script type="text/javascript">

            var subventana=window.open("index.html", "", "height=600, width=800");
            //sub_ventana.moveTo(0,0);
            subventana.resizeTo(800,600);
            document.write("<h1>Hola1</h1><br />");

            function realizar(){

                subventana.document.write("<h3>Hola2</h3><br />");

            }

            realizar();

        </script>
    </head>
    <body>
    </body>
</html>
    
answered by 02.12.2016 в 16:59
0

If you can just leave the name of the file empty:

<!DOCTYPE html>
<html lang="es">
    <head>
        <meta charset='utf-8'>
        <title></title>
        <style>
        </style>
        <script type="text/javascript">
            //En lugar de index.html lo dejé vacío 
            var subventana=window.open("", "", "height=600, width=800");
            subventana.resizeTo(800,600);
            document.write("<h1>Hola1</h1><br />");
            function realizar(){
                //Aquí agregué un div en la nuea ventana que es donde escribo el mensaje.
                subventana.document.write("<div id='hello'>Hola2<div>");
            }
            realizar();
        </script>
    </head>
    <body>
    </body>
</html>

A recommendation when you ask questions is to be more specific in the error so that others can help you.

    
answered by 02.12.2016 в 19:51