如何在浏览器标题中防止blob + guid [英] How to prevent blob + guid in browser title

查看:101
本文介绍了如何在浏览器标题中防止blob + guid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我正在做的是在服务器上生成一个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);

所有这些工作都很好,但每个浏览器都显示一个丑陋的字幕(如下所示): blob:2da57927-311e-4b3d-a261-d2679074802c



有什么办法摆脱这个小标题或用有意义的东西代替它?



编辑:
下面是改进代码的屏幕截图(应用VisioN的建议之后):

< iframe> ,它显示当前 Blob 数据,并根据需要设置弹出窗口样式:

  var win = open('','name','height = 300,width = 300'),
iframe = document.createElement('iframe'),
title = document.createElement('标题'),
文件=新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/


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

解决方案

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/

这篇关于如何在浏览器标题中防止blob + guid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆