snowberb – 11-12 Sep 19

How can I change the PDF title after using an iframe to display a base64 pdf? I tried with:
const newTab = window.open('');

if (newTab) {
newTab.document.title = documentName;
newTab?.document.write(
`<iframe title="${documentName}" width='100%' height='100%' src='data:application/pdf;base64,${encodeURI(
base64,
)}'></iframe>`,
);
}
const newTab = window.open('');

if (newTab) {
newTab.document.title = documentName;
newTab?.document.write(
`<iframe title="${documentName}" width='100%' height='100%' src='data:application/pdf;base64,${encodeURI(
base64,
)}'></iframe>`,
);
}
No description
UU
Unknown User211d ago
S
Sniberb211d ago
Tried like this and didnt work:
const newTab = window.open('');

if (newTab) {
newTab.onload = () => {
newTab.document.title = documentName;
};
newTab?.document.write(
`<iframe title="${documentName}" width='100%' height='100%' src='data:application/pdf;base64,${encodeURI(
base64,
)}'></iframe>`,
);
}
const newTab = window.open('');

if (newTab) {
newTab.onload = () => {
newTab.document.title = documentName;
};
newTab?.document.write(
`<iframe title="${documentName}" width='100%' height='100%' src='data:application/pdf;base64,${encodeURI(
base64,
)}'></iframe>`,
);
}
S
Sniberb211d ago
Btw im not trying to change the navigator tab name, I want to change the PDF file name
No description
S
Sniberb211d ago
No description
S
ScriptyChris210d ago
You want to change frame's title attribute? Try querying the iframe element and then just change its title attribute Something like :
newTab.document.querySelector(`[title="${documentTitle}"]`).title = 'new title' ;
newTab.document.querySelector(`[title="${documentTitle}"]`).title = 'new title' ;
S
Sniberb210d ago
no, the file name not the tab name I literally sent a screenshot
S
ScriptyChris210d ago
On what DOM element that file name is set? You should be able to modify, but i wonder why do you want to change the title instead of setting it already to the correct one? You could also try changing the title in the base64 - decode it, change title, encode and put back into the iframe
UU
Unknown User208d ago