Images in Javascript variables

P

Pete

Hi,

I have some image data in a Javascript variable, and I want to display
it. I have a technique which works in Firefox but not in Internet
Explorer :

<script>
var testImage = <image data as a string>
</script>

<img src="javascript:testImage"></img>


I understand that this should work in Javascript 1.2 and above, which
supports null characters in strings. Does anyone know why this doesn't
work in Internet Explorer?

Many thanks,
Pete.
 
M

Martin Honnen

Pete said:
I have some image data in a Javascript variable, and I want to display
it. I have a technique which works in Firefox but not in Internet
Explorer :

<script>
var testImage = <image data as a string>
</script>

<img src="javascript:testImage"></img>


I understand that this should work in Javascript 1.2 and above, which
supports null characters in strings. Does anyone know why this doesn't
work in Internet Explorer?

It is nowadays not as much a question of the JavaScript version but of
the browser supporting javascript: URLs for the HTML img element. I
think older versions of IE used to support XBM but newer don't, and IE
has never supported rendering GIF or JPG or PNG image data in a
javascript: URL as the src attribute value of an HTML img element.
 
P

Pete

Martin said:
It is nowadays not as much a question of the JavaScript version but of
the browser supporting javascript: URLs for the HTML img element. I
think older versions of IE used to support XBM but newer don't, and IE
has never supported rendering GIF or JPG or PNG image data in a
javascript: URL as the src attribute value of an HTML img element.

Thanks for the reply. So I guess the only way I could do it is to
somehow save the data to a file then point the img element at the file?

Hmmm. :-|
 
V

VK

Pete said:
So I guess the only way I could do it is to
somehow save the data to a file then point the img element at the file?

It depends on what kind of picture is that. If it's a raster photo then
I'm affraid so (or use server-side bitmap generator).

If it's a vector graphics (or something that can be represented as
vector graphics w/o nuking the parser) then you can use SVG/VML markup
or drawing commands.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top