admin管理员组

文章数量:1023131

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

Is this possible?

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

1) get base 64 code

2) decode it using js

3) generate iframe image

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

Is this possible?

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

1) get base 64 code

2) decode it using js

3) generate iframe image

Share Improve this question asked Jul 18, 2012 at 10:58 user669677user669677 2
  • Are you retrieving the base64 image from other website? – Jay Commented Jul 19, 2012 at 1:06
  • @Jay No. But I dont want to send a request to my site to decode base64. – user669677 Commented Jul 24, 2012 at 14:33
Add a ment  | 

2 Answers 2

Reset to default 1

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

    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.

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

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

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

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

Is this possible?

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

1) get base 64 code

2) decode it using js

3) generate iframe image

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

Is this possible?

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

1) get base 64 code

2) decode it using js

3) generate iframe image

Share Improve this question asked Jul 18, 2012 at 10:58 user669677user669677 2
  • Are you retrieving the base64 image from other website? – Jay Commented Jul 19, 2012 at 1:06
  • @Jay No. But I dont want to send a request to my site to decode base64. – user669677 Commented Jul 24, 2012 at 14:33
Add a ment  | 

2 Answers 2

Reset to default 1

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

    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.

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

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

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

本文标签: javascriptiframeset Content Type headerStack Overflow