How to prevent blob + guid in browser title

守給你的承諾、 提交于 2019-12-13 14:44:11

问题


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):


回答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 = 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/



来源:https://stackoverflow.com/questions/24451958/how-to-prevent-blob-guid-in-browser-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!