Last active
November 4, 2019 22:59
-
-
Save jmg/da839535e45c69ba81a26b9eb05f1c4f to your computer and use it in GitHub Desktop.
Recibe un archivo desde una pestaña (parent.html) mediante FileReader y postMessage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Child Window</title> | |
<script type="text/javascript"> | |
//esta funcion escucha eventos desde parent.html para recibir los datos del archivo | |
window.addEventListener('message', function(e) { | |
//convierto los datos en formato JSON a su "formato original" (objeto de javascript) | |
var message = JSON.parse(e.data); | |
if (message.type == "file") { | |
//muesto el archivo en el html de child.html | |
document.getElementById('file-content').innerText = message.data; | |
} | |
}); | |
//envio la señal de "ready" a parent.html | |
window.opener.postMessage("ready", '*'); | |
</script> | |
</head> | |
<body> | |
<div id="file-content"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment