When the code behind, I am able to open a new browser tab displaying a PDF document using data received as a blob from the server. The functionality works as expected, but I noticed that the title of the browser tab is displayed as some hexadecimal code. Is there a way to dynamically change this tab title to something more descriptive like "Document"?
Unfortunately, I'm unable to provide a StackBlitz sample since the data is coming from a server. Here is the code snippet I am currently using:
const file = new Blob([data], {type:'application/pdf'});
const fileURL = URL.createObjectURL(file);
window.open(fileURL, '_blank');
Here is how my browser tab currently appears:
https://i.sstatic.net/GkdSq.png
A potential solution (tested in Chrome and Edge) involves setting the title after opening the window:
var w = window.open(fileURL, '_blank');
setTimeout(function(){ w.document.title = 'My title'; }, 500);
Another solution (compatible with Chrome, Firefox, and Edge) involves directly writing HTML content to the opened window:
var w = window.open(fileURL, '_blank');
w.document.write('<html><head><title>My title</title></head><body height="100%" width="100%"><iframe src="' + fileURL+ '" height="100%" width="100%"></iframe></body></html>');