Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  59] [ 7]  / answers: 1 / hits: 7811  / 11 Years ago, thu, december 26, 2013, 12:00:00

I am using javascript. I have a pdf file stored on server which i need to open in new tab using javascript. I have tried the below code



function openPDF() {
var urlToPdfFile = http://www.demosite.com/pdf/demo.pdf; //something like this
window.open(urlToPdfFile);
}


But I keep getting error like below



Unknown content type requested.

URL: '/pdf/demo.pdf'.

Requested extension: '.pdf'.


This because I see the content-type is html in the request.



how can I open PDF in new tab using javascript, by providing the content-type...?



Thanks


More From » pdf

 Answers
1

Try this code, it works:



function openPDF(urlToPdfFile) {
window.open(urlToPdfFile, 'pdf');
}

openPDF('http://www.demosite.com/pdf/demo.pdf');

[#49219] Tuesday, December 24, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadap

Total Points: 101
Total Questions: 104
Total Answers: 98

Location: Mexico
Member since Sun, Jul 25, 2021
3 Years ago
;