Skip to content Skip to sidebar Skip to footer

How To Prevent Blob + Guid In Browser Title

Basically, what I am doing is generating a PDF file on the server and showing it in the browser via javascript like this: file = new window.Blob([data], { type: 'application/pdf'

Solution 1:

As I mentioned in the comments, one possible way is to make an <iframe> in the popup window, that displays the current Blob data, and to style the popup as you wish:

var win = open('', 'name', 'height=300, width=300'),
    iframe = document.createElement('iframe'),
    title = document.createElement('title'),
    file = newBlob([data], { type: 'application/pdf' }),
    fileUrl = URL.createObjectURL(file);

title.appendChild(document.createTextNode('Nice title :)'));

iframe.src = fileUrl;
iframe.width = '100%';
iframe.height = '100%';
iframe.style.border = 'none';

win.document.head.appendChild(title);
win.document.body.appendChild(iframe);
win.document.body.style.margin = 0;

DEMO:http://jsfiddle.net/MeY9e/

Solution 2:

You can simply add a settimeout to change the page title after the blob has been loaded in the new tab like this -

    newTab.location.href = URL.createObjectURL(blob); 
    setTimeout(function() {
        newTab.document.title = blob.name;
    }, 10);

Post a Comment for "How To Prevent Blob + Guid In Browser Title"