469,644 Members | 1,929 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,644 developers. It's quick & easy.

Insert binary data into HTML

multi
8
Hi all,
my question is :

is it possible to insert binary (like attachment) data into html, after that on client-side with javascript or ajax to get this data (download) from this html ?!
give me some ideas, hints or anything :(

Thank you !
Feb 5 '07 #1
4 10108
acoder
16,027 Expert Mod 8TB
Welcome to The Scripts.

I'm not sure I understand. HTML is client-side, so what do you mean by inserting binary data into HTML? Do you mean, you want to force a download when you come to a page? Do you want to use AJAX to get binary data from the server?
Feb 5 '07 #2
multi
8
i mean, you have a html document on the client side, who contains jpeg binary data of an jpeg in base64 encoding, i have js decoder from base64 to binary (something like that) an i want to, after pressing a button or something else some event... to starts "downloading" this data, from the html.
is it possible ?
Feb 5 '07 #3
acoder
16,027 Expert Mod 8TB
I don't know if this is possible on the client-side, but you can set the Content-Disposition header using server-side code which suggests to the browser how a file should be dealt with. Inline usually displays in the browser, but if you set it to 'attachment', it suggests that the user should be asked what to do (including saving to disk). Set the mime-type to image/jpg or whatever the file.

There is no foolproof reliable way to do this, but it should be possible by setting the correct headers.
Feb 5 '07 #4
UniDyne
18
If I am reading your question correctly, you want to pass some sort of encoded binary information in the HTML page to be read in by a JavaScript that is included on that page.

To do this, the binary content will need to be Base64 encoded or somesuch. Browsers get ugly when raw binary data appears in the HTML. There are plenty of places you can find a JavaScript Base64 decoder.

You can simply place the Base64 encoded content inside a hidden DIV tag or TEXTAREA. You could also use the <![CDATA[....]]> tag to hold the encoded data for extra safety. So, what you would have is something like this:

Expand|Select|Wrap|Line Numbers
  1. <div id="mydata" style="display:none"><![CDATA[SGVsbG8gV29ybGQh]]></div>
For a Base64 decoder, check http://rumkin.com/tools/compression/base64.php.
Feb 6 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Niraj | last post: by
20 posts views Thread by akej via SQLMonster.com | last post: by
11 posts views Thread by Chris Fink | last post: by
11 posts views Thread by Ted | last post: by
4 posts views Thread by mathon | last post: by
6 posts views Thread by Gregor =?UTF-8?B?S292YcSN?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.