Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 12, 2020 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/c1c3b73245caa9915f7dad8914969233 to your computer and use it in GitHub Desktop.
Save parzibyte/c1c3b73245caa9915f7dad8914969233 to your computer and use it in GitHub Desktop.
/*
Programado por Luis Cabrera Benito
____ _____ _ _ _
| _ \ | __ \ (_) | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
__/ | __/ |
|___/ |___/
Blog: https://parzibyte.me/blog
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
Contacto: https://parzibyte.me/blog/contacto/
*/
// Este script es incluido en la ventana que abre la principal
const $btnEnviar = document.querySelector("#btnEnviar"),
$mensaje = document.querySelector("#mensaje"),
$mensajeRecibido = document.querySelector("#mensajeRecibido");
$btnEnviar.addEventListener("click", () => {
const mensaje = $mensaje.value;
if (!mensaje) return alert("Escribe un mensaje");
if (window.opener) {
window.opener.establecerMensaje(mensaje);
}
});
// Definición de función desde la que nos llama el padre
window.establecerMensaje = function (mensaje) {
$mensajeRecibido.textContent = mensaje;
}
<!--
Programado por Luis Cabrera Benito
____ _____ _ _ _
| _ \ | __ \ (_) | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
__/ | __/ |
|___/ |___/
Blog: https://parzibyte.me/blog
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
Contacto: https://parzibyte.me/blog/contacto/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Ventana hija</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<input type="text" id="mensaje" placeholder="Enviar al padre">&nbsp;
<button id="btnEnviar">Enviar</button>
<br>
<p id="mensajeRecibido">Aquí aparece el mensaje recibido</p>
<script src="hija.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment