How to prevent blob + guid in browser title
Asked Answered
A

2

6

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' });
  var fileUrl = URL.createObjectURL(file);
  var wnd = window.open(fileUrl, "_blank", "location=no, fullscreen=yes, scrollbars=auto, width=" + screen.width + ",height=" + screen.height);

All this works fine but every browser is showing an ugly subtitle (something like this): blob:2da57927-311e-4b3d-a261-d2679074802c

Is there any way to get rid of this subtitle or to replace it with something meaningful?

Edited: Here is a screen capture of the improved code (after applying VisioN's suggestion):

enter image description here

Aurie answered 27/6, 2014 at 12:33 Comment(3)
I doubt if you can do this anyhow in cross-browser way, if only you don't display a plain HTML page with maximised <iframe> element, that outputs the blob contents.Tabriz
Save it somewhere and pass the link (server or S3)Matilda
Have you some short sample code how to do this?Aurie
T
7

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 = new Blob([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/

Tabriz answered 27/6, 2014 at 12:52 Comment(7)
Nice, works much better, but now instead of the blob + guid I get the following: about: blank.Aurie
@Aurie Strange. What browser do you use? I have the alternative title in Chrome and FF.Tabriz
I tried it with the newest chrome and firefox browsers. Both show the same. Even your jsfiddle sample shows this. Just below the main title there is a second title in white that says about: blank. I don't know if I can post an image on SO to show you.Aurie
I added a screen capture in my original post of what I get.Aurie
@Aurie Ah! This is not a title, this is an address bar, which couldn't be hidden in modern browsers. By default the address of the dynamically generated page is exactly "about:blank", but you may create a blank page on your server, say with file name pdf.html and pass this name as a first argument of open function: open('pdf.html', 'name', ...).Tabriz
Great, if needed by anybody, in chrome you get rid of the bar running it with the -app argument, like this: Chrome.exe --app=my.app.htm.Aurie
Can't save a pdf from within an iframe anyways :/Commination
L
1

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);
Latex answered 4/12, 2020 at 18:29 Comment(1)
What's 'newTab'?Elliott

© 2022 - 2024 — McMap. All rights reserved.