View Single Post
Old 01-19-2013, 04:33 AM   PM User | #13
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,554
Thanks: 9
Thanked 480 Times in 463 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
this works great in chrome, full FF support should kick in starting early spring:

Code:
function download(strData, strFileName, strMimeType){
  var  D=document, A=arguments, a=D.createElement("a"), 
       d=A[0], n=A[1], t=A[2]||"text/plain";

    //build download link:
       a.href="data:" +strMimeType+ "," +escape(strData);

if('download' in a){
     a.setAttribute("download", n);
     a.innerHTML="downloading...";
     D.body.appendChild(a);
    setTimeout(function(){
	var e= D.createEvent("MouseEvents");
	e.initMouseEvent(
		"click", true, false, window, 0, 0, 0, 0, 0
		, false, false, false, false, 0, null
	);
       a.dispatchEvent(e);
       D.body.removeChild(a);
    }, 66 );
  return true;
};//end if a[download]?

 //do iframe dataURL download:
    var f=D.createElement("iframe");
       D.body.appendChild(f);
        f.src="data:" +(A[2]?A[2]:"application/octet-stream")+ (window.btoa?";base64":"") +","  +(window.btoa?window.btoa:escape)(strData);
        setTimeout(function(){D.body.removeChild(f);}, 333);
    return true;
}//end download()
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5% IE10:8.5%
rnd me is online now   Reply With Quote