HTML and MIME

B

Brad

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
 
R

rf

Brad said:
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.
 
B

Brad

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
 
R

rf

Brad said:
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.
 
R

rf

rf said:
Why? Trying to bypass some security or something?


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

Brad

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
 

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,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top