javascript iframe - 设置内容类型标头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11539779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:35:41  来源:igfitidea点击:

iframe - set Content Type header

javascripthtmlinternet-explorer-7base64

提问by

I would like to display a JPEG image dynamically using iframe, but its header should be "Content-type: image/jpeg".

我想使用 iframe 动态显示 JPEG 图像,但它的标题应该是"Content-type: image/jpeg".

Is this possible?

这可能吗?

This would be a workaround for displaying base64 images in IE7:

这将是在 IE7 中显示 base64 图像的解决方法:

1) get base 64 code

1)获取base 64代码

2) decode it using js

2)使用js解码

3) generate iframe image

3) 生成 iframe 图像

回答by Onur Topal

Maybe I did not get what you actually need (especially decode it using js part) but you can try some thing like this

也许我没有得到你真正需要的(特别是使用 js 部分解码它)但你可以尝试这样的事情

    var data64 = "your encoded staf..."
    document.getElementById("divContent").innerHTML = "<iframe name='innerFrame' src='"+data64 +"'></iframe>";

Apparently the above code doesn t work for IE. you can use the below block instead.

显然上面的代码不适用于 IE。您可以改用下面的块。

    var data64 = "your encoded staf..."
    document.getElementById("divContent").innerHTML = "<iframe name='innerFrame'></iframe>";
    var objDoc = window.frames[ "innerFrame" ].document;
    objDoc.write("<img src='"+data64 +"' />");

you can also add an image to iframe document. But I would just use the adding a img tag to original page (parent page of the iframe.)

您还可以将图像添加到 iframe 文档。但我只会使用向原始页面(iframe 的父页面)添加 img 标签。

回答by paulslater19

You'd want to return the content-type from the server returning the iframe source.

您希望从返回 iframe 源的服务器返回内容类型。

In other words if your iframe looked like: <iframe src="http://www.foobar.com/test.php>, the test.phpshould set the content-type to image/jpeg

换句话说,如果您的 iframe 看起来像:<iframe src="http://www.foobar.com/test.php>test.php则应将内容类型设置为image/jpeg