By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,292 Members | 1,702 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,292 IT Pros & Developers. It's quick & easy.

Insert binary data into HTML

P: 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
Share this Question
Share on Google+
4 Replies

Expert Mod 15k+
P: 16,027
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

P: 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

Expert Mod 15k+
P: 16,027
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

P: 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
Feb 6 '07 #5

Post your reply

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