Here is the actual code:

function pdf(){ var widthImage = 400; var heightImage = 400; var newWin = open('','Печать','width='+ widthImage +',height='+ heightImage + ',status=no,toolbar=no,menubar=no,location=no,scrollbar=0,resizable=yes'); newWin.document.writeln('<html><head></head><body>pdf<hr><object><embed src=scr="www.bstu.ru/shared/attachments/82141" width="400" height="400" /></object></body></html>'); newWin.document.close(); newWin.focus(); //newWin.print(); //newWin.close(); } function jpg(){ var widthImage = 400; var heightImage = 400; var newWin = open('','Печать','width='+ widthImage +',height='+ heightImage + ',status=no,toolbar=no,menubar=no,location=no,scrollbar=0,resizable=yes'); newWin.document.writeln('<html><head></head><body>jpg<hr><img scr="www.dreempics.com/img/picture/Mar/25/9b1e838c79c65f22a6535a9a32a51387/mini_2.jpg"></body></html>'); newWin.document.close(); newWin.focus(); //newWin.print(); //newWin.close(); } 
 <button onclick="pdf();">pdf</button> <button onclick="jpg();">jpg</button> 

The markup works fine, but the files are not displayed. What is the reason?

---- Updated ------

 function pdf(){ var widthImage = 400; var heightImage = 400; var newWin = open('','Печать','width='+ widthImage +',height='+ heightImage + ',status=no,toolbar=no,menubar=no,location=no,scrollbar=0,resizable=yes'); newWin.document.writeln('<html><head></head><body>pdf<hr><object><embed src="http://www.bstu.ru/shared/attachments/82141" width="400" height="400" /></object></body></html>'); newWin.document.close(); newWin.focus(); //newWin.print(); //newWin.close(); } function jpg(){ var widthImage = 400; var heightImage = 400; var newWin = open('','Печать','width='+ widthImage +',height='+ heightImage + ',status=no,toolbar=no,menubar=no,location=no,scrollbar=0,resizable=yes'); newWin.document.writeln('<html><head></head><body>jpg<hr><img src="http://www.dreempics.com/img/picture/Mar/25/9b1e838c79c65f22a6535a9a32a51387/mini_2.jpg"></body></html>'); newWin.document.close(); newWin.focus(); //newWin.print(); //newWin.close(); } 
 <button onclick="pdf();">pdf</button> <button onclick="jpg();">jpg</button> 

Now only the PDF file is not displayed. What could be the reason?

    2 answers 2

    Links incorrectly indicated. If you want them to open you need to add http: // and also the src attributes are incorrectly written. jpg () is scr instead of src. I don’t know about pdf (), but the error is the same.

     function pdf(){ var widthImage = 400; var heightImage = 400; var newWin = open('','Печать','width='+ widthImage +',height='+ heightImage + ',status=no,toolbar=no,menubar=no,location=no,scrollbar=0,resizable=yes'); newWin.document.writeln('<html><head></head><body>pdf<hr><object><embed src="http://www.bstu.ru/shared/attachments/82141" width="400" height="400" /></object></body></html>'); newWin.document.close(); newWin.focus(); //newWin.print(); //newWin.close(); } function jpg(){ var widthImage = 400; var heightImage = 400; var newWin = open('','Печать','width='+ widthImage +',height='+ heightImage + ',status=no,toolbar=no,menubar=no,location=no,scrollbar=0,resizable=yes'); newWin.document.writeln('<html><head></head><body>jpg<hr><img src="http://www.dreempics.com/img/picture/Mar/25/9b1e838c79c65f22a6535a9a32a51387/mini_2.jpg"></body></html>'); newWin.document.close(); newWin.focus(); //newWin.print(); //newWin.close(); } 
     <button onclick="pdf();">pdf</button> <button onclick="jpg();">jpg</button> 

    • c src already figured out, now it's not clear why pdf doesn't open - perfect

    To open a pdf file in the embed tag, add the type="application/pdf" argument.