<!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/*">
<input type="file" id="textInput" accept=".txt">
<input type="file" id="folderInput" webkitdirectory directory multiple>
<button onclick="openNewWindow()">Abrir Nova Janela</button>
<script>
function openNewWindow() {
const userText = document.getElementById("userText").value;
const imageInput = document.getElementById("imageInput").files[0];
const textInput = document.getElementById("textInput").files[0];
const folderInput = document.getElementById("folderInput").files;
const newWindow = window.open("", "", "width=600,height=600");
newWindow.document.write("<p id='displayText'></p>");
newWindow.document.write("<img id='displayImage' style='max-width: 100%; height: auto;'>");
newWindow.document.write("<pre id='displayTextFile'></pre>");
newWindow.document.write("<ul id='displayFolderFiles'></ul>");
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;\">'; var textContent = document.getElementById('displayTextFile').innerText; window.opener.document.getElementById('demo').innerHTML += '<br>' + textContent; var folderFiles = document.getElementById('displayFolderFiles').innerHTML; window.opener.document.getElementById('demo').innerHTML += '<br>' + folderFiles; }<\/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);
}
if (textInput) {
const reader = new FileReader();
reader.onload = function(e) {
newWindow.document.getElementById('displayTextFile').innerText = e.target.result;
};
reader.readAsText(textInput);
}
if (folderInput.length > 0) {
for (let i = 0; i < folderInput.length; i++) {
const li = document.createElement('li');
li.textContent = folderInput[i].webkitRelativePath;
newWindow.document.getElementById('displayFolderFiles').appendChild(li);
}
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>The Window Object</h1>
<h2>The opener Property</h2>
<p id="demo">
Clique no botão para abrir uma nova janela onde você pode enviar arquivos.</p>
<input type="file" id="fileInput" multiple>
<br>
<button onclick="myFunction()">Enviar Arquivos</button>
<script>
function myFunction() {
const files = document.getElementById("fileInput").files;
const myWindow = window.open("", "", "width=300,height=300");
myWindow.document.write('<h1>Arquivos Recebidos</h1>');
myWindow.document.write('<ul id="fileList"></ul>');
myWindow.document.write('<br><button onclick="downloadFiles()">Baixar Arquivos</button>');
const fileList = myWindow.document.getElementById("fileList");
for (let i = 0; i < files.length; i++) {
const li = document.createElement("li");
li.textContent = files[i].name;
fileList.appendChild(li);
}
myWindow.downloadFiles = function() {
for (let i = 0; i < files.length; i++) {
const file = files[i];
const reader = new FileReader();
reader.onload = function(e) {
const blob = new Blob([e.target.result], { type: file.type });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = file.name;
link.click();
};
reader.readAsArrayBuffer(file);
}
};
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Abrir Nova Janela</title>
<script>
function abrirNovaJanela() {
window.open("pesquisa.html", "Nova Janela", "width=800,height=600");
}
</script>
</head>
<body>
<button onclick="abrirNovaJanela()">Abrir Nova Janela</button>
<h1>Pesquisa Avançada</h1>
<form action="https://www.google.com/search" method="get" target="_blank">
<input type="text" name="q" placeholder="Digite sua pesquisa">
<button type="submit">Pesquisar</button>
</form>
</body>
</html>