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

115
Visualizações
Download a Data URL using Safari

we are developping an app where we need to download a PDF file generated on the client side. We are using a string to feed the contents of the file into a data URL, like so:

const pdfContent = 'xxxxx';
    const element = document.createElement('a');
    element.setAttribute('href', `data:application/pdf;charset=utf-8,${encodeURIComponent(pdfContent)}`);
    element.setAttribute('download', 'mypdf.pdf');
    element.style.display = 'none';

    document.body.appendChild(element);

    element.click();

    document.body.removeChild(element);

This works very well using Microsoft Edge, but it bugs out in Safari saying 'not allowed to navigate top frame to data URL'.

The host application does not allow for window.open() or any such tricks, I tried using an iframe but it wouldn't work, amybe I did it wrong. I also tried other libraries like file-saver, save-file, all available on npm with the same result, cannot navigate top frame to data url.

Any hints? Thanks.

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

0

I ended up using a blob stream, which partially worked, because I'm still unable to download because it is running on a sandboxed environment (Office add-in). I guess we'll have to resort to opening a browser window and downloading a file there, unless someone has a better alternative for Office add-ins.

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