I have the following code js when I execute the function "write ()" with a button event, I get the following error "Can not read property 'closed' of undefined" in the if of the function, can you help me?
var nuevaventana;
function crearnuevaventana()
{
var nuevaventana = window.open("", "nueva ventana", "status, heigth=200 width=300");
}
function escribe()
{
if (nuevaventana.closed)
{
crearnuevaventana();
}
nuevaventana.focus();
var contenido = "<html><head><title>Nueva Ventana</title></head>";
contenido += "<body bgcolor='coral'> <h1>Hola mundo</h1>";
contenido += "</body> </html>";
nuevaventana.document.write(contenido);
nuevaventana.document.closed;
}