Created
September 23, 2014 04:38
-
-
Save jtyjty99999/26672f2b13aefe3af91c to your computer and use it in GitHub Desktop.
save as
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
function saveAs(blob, filename) { | |
var type = blob.type; | |
var force_saveable_type = 'application/octet-stream'; | |
if (type && type != force_saveable_type) { // 强制下载,而非在浏览器中打开 | |
var slice = blob.slice || blob.webkitSlice; | |
blob = slice.call(blob, 0, blob.size, force_saveable_type); | |
} | |
var url = URL.createObjectURL(blob); | |
var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a'); | |
save_link.href = url; | |
save_link.download = filename; | |
var event = document.createEvent('MouseEvents'); | |
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
save_link.dispatchEvent(event); | |
URL.revokeObjectURL(url); | |
} | |
var URL = URL || webkitURL || window; | |
var bb = new Blob([JSON.stringify($scope.maps, null, '\t')], {type: 'text/json'}); | |
saveAs(bb, 'ReResSetting.json'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment