Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
¿Existe alguna alternativa para document.execCommand('SaveAs', null, 'myFile.html'); en navegadores chromium (Microsoft-Edge)

Necesito guardar un archivo html desde el método window.open, document.execCommand('SaveAs', null, 'abc.html'); resuelve el propósito en Internet Explorer pero el mismo script no funciona en Microsoft-Edge (chromium).

He usado Window.showSaveFilePicker() para guardar los archivos en Chrome, pero puedo pasar una cadena codificada. Necesito obtener los datos de Window.Open HTML file y guardarlo usando microsoft-edge.

Necesita conocer un código común que funcione tanto en Internet Explorer como en Microsoft-Edge (chromium)

Gracias

//Índice.html

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="Index.js"></script> </head> <body> <button type="button" onclick="onSaveInIE()">In IE</button> <button type="button" onclick="onSaveInChrome()">In Chrome</button> </body> </html>

//Índice.js

 function onSaveInIE() { var csvWindow = openNewWindowObj(); csvWindow.document.execCommand('SaveAs', null, 'abc.html'); csvWindow.close(); } function openNewWindowObj() { var newWindowObj = window.open("window.html", "New popup Window", 'height=200,width=150') newWindowObj.focus(); return newWindowObj; } async function onSaveInChrome() { let fileHandle = await window.showSaveFilePicker(); const writeable = await fileHandle.createWritable(); await writeable.write("DummyData"); writeable.close(); }

//ventana.html

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <b>From popup window</b> </body> </html>

funciona en IE

error en cromo

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Creo que puedes intentar usar diferentes métodos en diferentes navegadores. Consulte este caso , determine el navegador utilizado.

Además, si necesita guardar el contenido de la página abierta por window.open() en Edge, puede intentar obtener su identificador después de cargar la página y luego obtener su elemento DOM.

Una demostración sencilla:

 function onSaveInIE() { var csvWindow = openNewWindowObj(); csvWindow.document.execCommand('SaveAs', null, 'filename.html'); csvWindow.close(); } function openNewWindowObj() { var newWindowObj = window.open("window.html", "New popup Window", 'height=200,width=150') newWindowObj.focus(); return newWindowObj; } function onSaveInChrome() { var csvWindow = openNewWindowObj(); csvWindow.onload = function () { popupHtml = csvWindow.document.documentElement.outerHTML; download('filename.html', popupHtml); csvWindow.close(); } } function download(filename, text) { var element = document.createElement('a'); element.setAttribute('href', 'data:text/html;charset=utf-8,' + encodeURIComponent(text)); element.setAttribute('download', filename); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda