<!DOCTYPE html>
<html>
<body>
<h1>The Window Object</h1>
<h2>The opener Property</h2>
<p id="demo">
Click the button to open a new window that writes "HELLO!" in the opener window.</p>
<textarea id="userText" placeholder="Escreva algo aqui..."></textarea>
<button onclick="openNewWindow()">Abrir Nova Janela</button>
<script>
function openNewWindow() {
const userText = document.getElementById("userText").value;
const newWindow = window.open("", "", "width=300,height=300");
newWindow.document.write("<p id='displayText'></p>");
newWindow.document.write("<button onclick='sendText()'>Enviar Texto</button>");
newWindow.document.write("<script>function sendText() { window.opener.document.getElementById('demo').innerHTML = document.getElementById('displayText').innerHTML; }<\/script>");
newWindow.document.write("<script>document.getElementById('displayText').innerHTML = '" + userText + "';<\/script>");
}
</script>
</body>
</html>
<---------------------------------------------------------------------->
Server entre janelas window.
<!DOCTYPE html>
<html>
<body>
<h1>The Window Object</h1>
<h2>The opener Property</h2>
<p id="demo">
Click the button to open a new window that writes "HELLO!" in the opener window.</p>
<textarea id="userText" placeholder="Escreva algo aqui..."></textarea>
<input type="file" id="imageInput" accept="image/*">
<button onclick="openNewWindow()">Abrir Nova Janela</button>
<script>
function openNewWindow() {
const userText = document.getElementById("userText").value;
const imageInput = document.getElementById("imageInput").files[0];
const newWindow = window.open("", "", "width=300,height=300");
newWindow.document.write("<p id='displayText'></p>");
newWindow.document.write("<img id='displayImage' style='max-width: 100%; height: auto;'>");
newWindow.document.write("<button onclick='sendContent()'>Enviar Conteúdo</button>");
newWindow.document.write("<script>function sendContent() { window.opener.document.getElementById('demo').innerHTML = document.getElementById('displayText').innerHTML; var imgSrc = document.getElementById('displayImage').src; window.opener.document.getElementById('demo').innerHTML += '<br><img src=\"' + imgSrc + '\" style=\"max-width: 100%; height: auto;\">'; }<\/script>");
newWindow.document.write("<script>document.getElementById('displayText').innerHTML = '" + userText + "';<\/script>");
if (imageInput) {
const reader = new FileReader();
reader.onload = function(e) {
newWindow.document.getElementById('displayImage').src = e.target.result;
};
reader.readAsDataURL(imageInput);
}
}
</script>
</body>
</html>