Skip to content

Instantly share code, notes, and snippets.

@Grassboy
Last active October 29, 2015 03:10
Show Gist options
  • Save Grassboy/c3b2b44847dc7eec7c5f to your computer and use it in GitHub Desktop.
Save Grassboy/c3b2b44847dc7eec7c5f to your computer and use it in GitHub Desktop.
get the dataURL of specific url
var gDataURL = function(opts){
opts = opts || {};
opts.onload = opts.onload || function(r){
console.log(r);
};
opts.url = opts.url || location.href;
var oReq = new XMLHttpRequest();
oReq.open("GET", opts.url, true);
oReq.responseType = "blob";
oReq.setRequestHeader("Accept", "*/*");
oReq.setRequestHeader("Accept-Encoding", "deflate");
oReq.onload = function(oEvent) {
var blob = oReq.response;
var reader = new FileReader();
reader.onload = function(oFREvent) {
opts.onload(oFREvent.target.result);
};
reader.readAsDataURL(blob);
};
oReq.send();
};
gDataURL({url: 'http://is.gy/', onload: function(r){alert(r)}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment