如何防止浏览器标题中出现 blob + guid

2024-02-07

基本上,我正在做的是在服务器上生成一个 PDF 文件并通过 javascript 在浏览器中显示它,如下所示:

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

所有这些工作正常,但每个浏览器都显示一个丑陋的字幕(类似这样):斑点:2da57927-311e-4b3d-a261-d2679074802c

有什么办法可以去掉这个副标题或者用有意义的东西代替它吗?

Edited:以下是改进代码的屏幕截图(应用 VisioN 的建议后):


正如我在评论中提到的,一种可能的方法是制作<iframe>在弹出的窗口中,显示当前Blob数据,并根据需要设置弹出窗口的样式:

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/ http://jsfiddle.net/MeY9e/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何防止浏览器标题中出现 blob + guid 的相关文章