Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open PDF Stream in New Window with Javascript

How do you open a new window that displays the streamed response of an AJAX request?

like image 612
Poyan Avatar asked Jul 17 '26 11:07

Poyan


1 Answers

Other similar questions presuppose a scenario where the response has a defined url, other answers are kind of old.

For modern browsers, you use fetch you can can call blob() on the returned response and then use URL.createObjectURL() to create a temporary url that you can open as normal with window.open().

Full example is something like

fetch(urlThatReturnsDataOpenableByBrowser)
    .then(response => response.blob())
    .then(data => window.open(URL.createObjectURL(data)))
like image 193
Poyan Avatar answered Jul 19 '26 01:07

Poyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!