Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
42
rated 0 times [  43] [ 1]  / answers: 1 / hits: 22423  / 8 Years ago, wed, november 23, 2016, 12:00:00

I am opening a new tab to display a PDF file. I have the PDF file data on a bytearray, base 64.



I am able to get the data, and display it doing this:



downloadFile(strData, name) {
var newdata = data: + application/pdf + ;base64, + (strData);
var newWindow = window.open(newdata, _blank);
newWindow.onload = function() { document.title = My title; }
return true;
}


The problem i am having is that i am not able to set the title to the new tab opened.



I would like to set a title like PDF File or just the name of the document (i am getting the file data and the file name separately and passing it to my downloadFile function.



Is there any way to set the title to this tab? Thanks in advance!


More From » html

 Answers
36

Try this:



  ....
var newWindow = window.open(newdata, _blank);
newWindow.document.title = Some title;
....


EDIT:



Another way to do this might be to send an iframe to a new window instead of opening it directly with the base64 string.



So something like:



var newWindow = window.open();
newWindow.document.write('<iframe src=data:application/pdf;base64,' + (strData) + ' frameborder=0 allowfullscreen></iframe>');
newWindow.document.title = Your Title Here;

[#59941] Tuesday, November 22, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
orlando

Total Points: 413
Total Questions: 92
Total Answers: 96

Location: Mauritania
Member since Sun, Oct 17, 2021
3 Years ago
;