Images in Javascript variables

Discussion in 'Javascript' started by Pete, Oct 30, 2006.

  1. Pete

    Pete Guest

    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.
     
    Pete, Oct 30, 2006
    #1
    1. Advertising

  2. Pete wrote:

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

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Oct 30, 2006
    #2
    1. Advertising

  3. Pete

    Pete Guest

    Martin Honnen wrote:
    >
    > 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. :-|
     
    Pete, Oct 30, 2006
    #3
  4. Pete

    VK Guest

    Pete wrote:
    > 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.
     
    VK, Oct 30, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGFuaWVsIFdlbGxlc2xleQ==?=

    Preloading Images into Javascript variables

    =?Utf-8?B?RGFuaWVsIFdlbGxlc2xleQ==?=, Aug 4, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    284
    =?Utf-8?B?RGFuaWVsIFdlbGxlc2xleQ==?=
    Aug 4, 2004
  2. =?Utf-8?B?RGFuaWVsIFdlbGxlc2xleQ==?=

    Preloading Images into Javascript variables

    =?Utf-8?B?RGFuaWVsIFdlbGxlc2xleQ==?=, Aug 7, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    453
    =?Utf-8?B?RGFuaWVsIFdlbGxlc2xleQ==?=
    Aug 7, 2004
  3. Guest
    Replies:
    4
    Views:
    921
    Eliyahu Goldin
    Jan 4, 2005
  4. sagejoshua
    Replies:
    16
    Views:
    674
    Michael Winter
    Nov 9, 2005
  5. Replies:
    9
    Views:
    995
Loading...

Share This Page