When I write weblog entries, I often find myself thinking, “I’d really like to write some markup where the user can just click a button and save what I’ve written. Uploading files to my weblog is a pain.”
Not any longer! Courtesy of the data: protocol, it is now fairly easy to write a fragment of HTML markup and use this script to quickly convert text in a webpage to a format Mozilla can save to your hard drive!
<form action="javascript:void()"> <fieldset><legend>saveAsFile.js</legend> <textarea rows="10" cols="80" id="saveAs" readonly="readonly"> <!-- Use whatever id you want, and stick the contents you want the user to save in here. --> </textarea><br> <button onclick="saveAsFile('saveAs', 'application/octet-stream')" type="button">Save File</button> </fieldset> </form>
The second argument is optional; it simply specifies a content-type for the textarea’s contents. If you omit it, the script assumes “application/octet-stream”, which is commonly used for downloads.
The only downside to this script is it doesn’t specify the filename through the data: protocol. That’s not allowed in the protocol, so the user has to manually specify the filename. Hence why I included the filename in the legend element.
Here’s the script, ready for you to save per the instructions.
Enjoy!
Its all about data:
http://segment7.net/projects/ruby/datafy/
(From Alex: Hey, I never said I was the first to think of it. Ian Hickson’s data: URI kitchen is another good tool.)