Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > HTML and MIME

Reply
Thread Tools

HTML and MIME

 
 
Brad
Guest
Posts: n/a
 
      06-12-2004
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


 
Reply With Quote
 
 
 
 
rf
Guest
Posts: n/a
 
      06-12-2004

"Brad" <(E-Mail Removed)> wrote in message
news:F4Cyc.7239$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
 
Brad
Guest
Posts: n/a
 
      06-12-2004
>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


 
Reply With Quote
 
rf
Guest
Posts: n/a
 
      06-12-2004

"Brad" <(E-Mail Removed)> wrote in message
news:UzCyc.7245$(E-Mail Removed)...
> >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.



 
Reply With Quote
 
rf
Guest
Posts: n/a
 
      06-12-2004

"rf" <(E-Mail Removed)> wrote in message
news:B8Dyc.11691$(E-Mail Removed)...
>
> "Brad" <(E-Mail Removed)> wrote in message
> news:UzCyc.7245$(E-Mail Removed)...
> > >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.


 
Reply With Quote
 
Brad
Guest
Posts: n/a
 
      06-12-2004
> > 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Email::MIME and Email::MIME::Attachment::Stripper ecureuil Perl Misc 0 05-28-2006 01:47 AM
tomcat 4.x : setting mime type for a directory or setting a default mime type CJ Java 1 10-29-2004 07:51 PM
how 2 convert mime to txt or extract words from mime joe Perl Misc 0 04-07-2004 12:34 AM
MIME::Lite HTML message handling John B. Kim Perl 1 01-19-2004 02:13 PM
Receiving zip files via Mime::Parser/Mime::Decoder Jan Arickx Perl Misc 0 08-25-2003 08:24 PM



Advertisments