Creating Data URIs

Inspired by this whatwg thread about fragment identifiers in data URIs where it was proposed to allow raw '#' in the URI's data to be treated as text instead of the start of a fragment identifier so authors don't have to percent-encode '#' as %23 (which I disagree that authors should be allowed to do that), I created this page to properly create text-based data URIs.

The page automatically encodes '#' as %23 in the data so that it doesn't get treated as a fragment identifier. There's also a field to have a real fragment identifier at the end of the URI, which is useful for text/html data URIs to jump to a certain element on the page.

Since that page only creates text-based data URIs, I lazily set up another page for files. The page just uses javascript and Opera's File API support to create the data URI. It doesn't submit anything to the server and the page can be used locally.

Those pages were inspired by my javascript uri and mailto uri pages.

Testing with data URIs in Opera, I found a long time ago (and still true now) that a user can't type or paste very long of a data URI into Opera's address field without Opera clipping the data. I forget, but I think the limit is 32K. Other browsers support a lot longer of a URI. To workaround this in Opera, you have to the data URI or present it as a link to click on. Then, Opera will accept a longer URI. Opera gets really annoying with this, but Opera has always had 32k limits like these in various places (the command line, css until recently, the "To" field in Opera's built-in mail client etc.).

Leave a Reply

Your email address will not be published. Required fields are marked *