How to show PDF on a new IE tab without loading it

IE seems to not allow drops to be opened directly. You should use msSaveOrOpenBlob. But is there any way to convert it later. I need to show the PDF to a new IE tab without loading it, or at least the user should not interact and not see that it is loading, for example. system temp. Safai opens it in the same window instead of a new tab, but IE is the main problem. The basic idea is to make all browsers look alike and open them in a new tab for preview.

let blob = new Blob([response], {
    type: 'application/pdf'
});

if (window.navigator && window.navigator.msSaveOrOpenBlob) {//IE
    window.navigator.msSaveOrOpenBlob(response, "TheDocumentToShow.pdf");
} else {
    var fileURL = URL.createObjectURL(response);
    if (navigator.userAgent.indexOf("Chrome") != -1 || navigator.userAgent.indexOf("Firefox") != -1){
        let win = window.open(fileURL, '_blank');                        
    } else { //Safari & Opera iOS
        window.location.href = fileURL;
    }
}
+5
source share
6 answers

a IE11, Edge Chrome:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <a href="file.pdf" target="_blank">Click</a>
</body>
</html>

PDF , .

+2

pdfjs https://mozilla.imtqy.com/pdf.js/

Viewer.php, pdf , , example.com/viewer.php?pdfLink=/files/path/to/doc.pdf

+1
<script>
function pdf() {
window.open("filename.pdf","_blank");
}
</script>
<div onclick="pdf();">Click here</div>

, ? . .

+1

(https://www.npmjs.com/package/ng2-pdfjs-viewer). PDF . [externalWindow]="true".


<ng2-pdfjs-viewer [externalWindow]="true" pdfSrc="samplepdf.pdf"></ng2-pdfjs-viewer>

+1

, -. , , - . - www.example.com/path/to/pdf_file.

pdf .

Set the title Content-dispositionto inline;filename=<your pdf filename>This ensures that the content of the response should not be downloaded.

I would share the backend code with him if I knew which backend you are using.

0
source

Source: https://habr.com/ru/post/1694838/


All Articles