Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript blob window open fires browser popup

I have a download operation in my javascript code with angularjs $http provider.

$http({
    method: "POST",
    url: "http://localhost:28494/api/print",
    data: data,
    responseType:'arraybuffer'
}).then(
    function (response) {

        var file = new Blob([response.data], {type: 'application/pdf'});

        var objectUrl = URL.createObjectURL(file);

        window.open(objectUrl,'_blank');         
    }
);

This fires my browser popup. I do not want to this.

enter image description here

But I want to download directly. Do not show the popup.

like image 252
barteloma Avatar asked Aug 11 '26 09:08

barteloma


1 Answers

You should use window.location.assign(objectUrl);. This forces the window to open and display the url. In your case it will download the file.

like image 73
Deividas Karzinauskas Avatar answered Aug 12 '26 23:08

Deividas Karzinauskas



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!