Sniberb
Sniberb11mo ago

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
8 Replies
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Sniberb
Sniberb11mo 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>`,
);
}
Sniberb
Sniberb11mo ago
Btw im not trying to change the navigator tab name, I want to change the PDF file name
No description
Sniberb
Sniberb11mo ago
No description
ScriptyChris
ScriptyChris11mo 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' ;
Sniberb
Sniberb11mo ago
no, the file name not the tab name I literally sent a screenshot
ScriptyChris
ScriptyChris11mo 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
reactibot
reactibot11mo ago
This thread hasn’t had any activity in 36 hours, so it’s now locked. Threads are closed automatically after 36 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1153649839402397707