Answer the question
In order to leave comments, you need to log in
Why doesn't the "download" button work on a new tab in Chrome PDF viewer after window.open()?
I am working on a project that receives data from a server via Spring boot in the form of an OutputStream. On the front, I am getting a PDF file represented as an array of bytes. I need to open it in a new tab. For this I use window.open() in js code. Here is the code to process the response from the server and open the file in a new tab.
fetch(options.url, options)
.then(response => {
return response.blob();
})
.then(blob => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = () => {
const data = reader.result
const tab = window.open();
tab.document.write("<html>" +
"<body>" +
"<embed type='application/pdf' " +
"style='position:absolute; left: 0; top: 0;' " +
"width='100%' " +
"height='100%' " +
"src='" + data +"'/>" +
"</body>" +
"</html>")
}
})
URL.createObjectURL(response.blob())
, but the browser opened it for a moment and then immediately closed it. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question