HTML and MIME

Discussion in 'HTML' started by Brad, Jun 12, 2004.

  1. Brad

    Brad Guest

    Hi,

    I have a HTML-page with a couple of JavaScript functions. One of the
    functions holds a variable of 18.000 bytes. This really is a jpg-image
    converted to a string (hopefully). The next step is to display the jpg in a
    new browser-window where the source is a variable, not the usual file. I've
    tried to generate HTML to handle this like this:

    var winFeatures = 'height=600,width=600,dependent' ;
    Document = window.open('','',winFeatures) ;
    Document.document.write ('<html><body>');
    Document.document.write (''<head>');
    Document.document.write ('<meta http-equiv="Content-Type"
    content="image/jpg">');
    Document.document.write ('</head>');
    for (iCount = 0; iCount < sResult.length; iCount++)
    {
    Document.document.write (sResult.charAt(iCount));
    }
    Document.document.write ('</body></html>');

    But al I get is garbage. I also tried the <img>-tag, same result. Any hints
    ?

    Regards
    Brad
     
    Brad, Jun 12, 2004
    #1
    1. Advertising

  2. Brad

    rf Guest

    "Brad" <> wrote in message
    news:F4Cyc.7239$...
    > Hi,
    >
    > I have a HTML-page with a couple of JavaScript functions. One of the
    > functions holds a variable of 18.000 bytes.


    Oh dear. What ever for.

    > This really is a jpg-image
    > converted to a string (hopefully). The next step is to display the jpg in

    a
    > new browser-window where the source is a variable, not the usual file.

    I've
    > tried to generate HTML to handle this like this:


    This is simply *not going to work*.

    > var winFeatures = 'height=600,width=600,dependent' ;
    > Document = window.open('','',winFeatures) ;
    > Document.document.write ('<html><body>');
    > Document.document.write (''<head>');
    > Document.document.write ('<meta http-equiv="Content-Type"
    > content="image/jpg">');
    > Document.document.write ('</head>');
    > for (iCount = 0; iCount < sResult.length; iCount++)
    > {
    > Document.document.write (sResult.charAt(iCount));
    > }
    > Document.document.write ('</body></html>');


    All this is going to achieve is to write, to the HTML page, the binary
    contents of your "image". It will not cause the browser to display that
    image. The element will be totally ignored. The browser is, after all,
    downloading a text file. Just lying about the contents of that file in a
    meta element is not going to make the page into a jpeg.

    > But al I get is garbage. I also tried the <img>-tag, same result. Any

    hints

    Use a real image element?

    Why on earth are you doing this anyway. If you were to state the real
    problem then maybe a real solution will be forthcoming :)

    Cheers
    Richard.
     
    rf, Jun 12, 2004
    #2
    1. Advertising

  3. Brad

    Brad Guest

    >Why on earth are you doing this anyway. If you were to state the real
    > problem then maybe a real solution will be forthcoming :)


    OK. The point is that I'm trying to print from a Java-applet _without_
    signing the applet or using JWS. The print-image is represented as a jpg in
    the applet. I convert the jpg to a string, converting each byte to its
    two-byte hex code (ie. the string is twice the size of the actual image).
    Since it's a public variable, I can read it in from a JavaScript. The
    JavaScript convert the string back to binary data, and voila -- all set for
    printing ! Wouldn't that be great ?

    Brad
     
    Brad, Jun 12, 2004
    #3
  4. Brad

    rf Guest

    "Brad" <> wrote in message
    news:UzCyc.7245$...
    > >Why on earth are you doing this anyway. If you were to state the real
    > > problem then maybe a real solution will be forthcoming :)

    >
    > OK. The point is that I'm trying to print from a Java-applet _without_
    > signing the applet or using JWS.


    Why? Trying to bypass some security or something?

    > The print-image is represented as a jpg in
    > the applet. I convert the jpg to a string, converting each byte to its
    > two-byte hex code (ie. the string is twice the size of the actual image).
    > Since it's a public variable, I can read it in from a JavaScript. The
    > JavaScript convert the string back to binary data, and voila -- all set

    for
    > printing ! Wouldn't that be great ?


    Yeah, OK. It's still not going to happen.

    Cheers
    Richard.
     
    rf, Jun 12, 2004
    #4
  5. Brad

    rf Guest

    "rf" <> wrote in message
    news:B8Dyc.11691$...
    >
    > "Brad" <> wrote in message
    > news:UzCyc.7245$...
    > > >Why on earth are you doing this anyway. If you were to state the real
    > > > problem then maybe a real solution will be forthcoming :)

    > >
    > > OK. The point is that I'm trying to print from a Java-applet _without_
    > > signing the applet or using JWS.

    >
    > Why? Trying to bypass some security or something?
    >
    > > The print-image is represented as a jpg in
    > > the applet. I convert the jpg to a string, converting each byte to its
    > > two-byte hex code (ie. the string is twice the size of the actual

    image).
    > > Since it's a public variable, I can read it in from a JavaScript. The
    > > JavaScript convert the string back to binary data, and voila -- all set

    > for
    > > printing ! Wouldn't that be great ?

    >
    > Yeah, OK. It's still not going to happen.


    Let me expand on that.

    You feed the browser a string of data, by pointing it to a web page.
    Additionally you can use javascript to add things to this stream, as in
    document.write.

    The browser interprets this string of *ascii* data into a DOM. You have
    heard of the Document Object Model?

    Within the DOM are elements. That is why we call things like <img> elements.
    You can also use javascript to manipulate the DOM, changing the elements
    attributes or even adding or removing elements.

    Now, one particular element has an unusual effect on the browser. The <img>
    element causes the browser to displays an image on the canvas. The image it
    displays is whatever is mentioned in image elements src attribute. That is
    the only way (well not the only way but the only way as far as this thread
    is concerned) that the browser will ever display a jpeg. All of this is
    *ascii*, not binary, not two byte hex codes.

    You can throw something like document.write("<img src="xxx">) at a browser
    and it will display the image at location xxx.

    If you throw document.write([the contents of a jpeg]) at a browser, what
    would you now expect. How is the browser going to interperet the string of
    characters you have provided and integrate them into the DOM.

    Badly :)

    Cheers
    Richard.
     
    rf, Jun 12, 2004
    #5
  6. Brad

    Brad Guest

    > > Why? Trying to bypass some security or something?

    No. It's just that the jpg from the applet is only the first half of the
    printout, the rest is stuff from the web-server. It would be neat to mix
    both parts in a new browser-window and then let the user press the browsers
    'print'-button.

    > If you throw document.write([the contents of a jpeg]) at a browser, what
    > would you now expect. How is the browser going to interperet the string of
    > characters you have provided and integrate them into the DOM.
    >
    > Badly :)


    OK, thanks ! I think I'll skip the idea as unusable !

    Since there is a web-server involved here, there is a second way to go.
    Submit the whole page to the web-server, write som server-code that extracts
    and converts the variable, creates a jpg-file, and then create a new
    HTML-page where images are displayed the usual way.

    Anyway, thanks for extensive and enlightning answer.

    Brad
     
    Brad, Jun 12, 2004
    #6
    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. John B. Kim

    MIME::Lite HTML message handling

    John B. Kim, Jan 18, 2004, in forum: Perl
    Replies:
    1
    Views:
    1,711
    Joe Smith
    Jan 19, 2004
  2. CJ
    Replies:
    1
    Views:
    1,586
    Andrew Thompson
    Oct 29, 2004
  3. Jan Arickx
    Replies:
    0
    Views:
    209
    Jan Arickx
    Aug 25, 2003
  4. joe
    Replies:
    0
    Views:
    210
  5. ecureuil
    Replies:
    0
    Views:
    342
    ecureuil
    May 28, 2006
Loading...

Share This Page