Skip to content

Instantly share code, notes, and snippets.

@MikeNats
Forked from jweir/protovis_to_link.js
Last active August 29, 2015 14:15
Show Gist options
  • Save MikeNats/27800b5687bb52788330 to your computer and use it in GitHub Desktop.
Save MikeNats/27800b5687bb52788330 to your computer and use it in GitHub Desktop.
// This example was created using Protovis & jQuery
// Base64 provided by http://www.webtoolkit.info/
function encode_as_img_and_link(){
// Add some critical information
$("svg").attr({ version: '1.1' , xmlns:"http://www.w3.org/2000/svg"});
var svg = $("#chart-canvas").html();
var b64 = Base64.encode(svg);
// Works in recent Webkit(Chrome)
$("body").append($("<img src='data:image/svg+xml;base64,\n"+b64+"' alt='file.svg'/>"));
// Works in Firefox 3.6 and Webit and possibly any browser which supports the data-uri
$("body").append($("<a href-lang='image/svg+xml' href='data:image/svg+xml;base64,\n"+b64+"' title='file.svg'>Download</a>"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment