Last active
October 29, 2015 03:10
-
-
Save Grassboy/c3b2b44847dc7eec7c5f to your computer and use it in GitHub Desktop.
get the dataURL of specific url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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