data: is the new “Bookmarklet”
Saturday, August 28th, 2010 23:15A data:
URL directly contains its content; for example, data:text/plain,Hello%20World!
. The main usefulness of this is that you can do things like including images inline in a document. But you can also use it to create 'anonymous' HTML documents, where any link to them or bookmark contains the entire document.
I originally did this in 2006 when I was in need of a URL-encoding tool and did not have one to hand; so I wrote out:
data:text/html,<form action="data:text/plain,"><input id=r>
Properly encoded, that's:
data:text/html,%3Cform%20action=%22data:text/plain,%22%3E%3Cinput%20name=r%3E
This produces a form with a single field which, when submitted, will generate a data URL for a plain text document containing “?r=” and then the text; the URL, then, will contain the entered text URL-encoded after the “?r=”.
Of course, that's a horrible kludge and JavaScript has an encodeURI
function...
See my site for the rest of that thought and more examples. (I can't include any actual data URLs in this post because LiveJournal doesn't permit them, for necessary but unfortunate reasons — the origin, in the sense of same-origin policy, of a data URL is the origin of the page containing it.)