Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,350
    Thanks
    11
    Thanked 589 Times in 570 Posts
    Quote Originally Posted by Airblader View Post
    Why do you insist on JavaScript? I gave you an alternative that is much more stable. For pure JavaScript to be able to do this cross-browser and reliably you will have to wait – indefinitely.
    well, this IS a javascript forum, so one would expect a javascript answer.

    just because you called JS out, here is a download function that works in current versions of IE, FF, and Chrome:

    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 (window.MSBlobBuilder) {
    		var bb = new MSBlobBuilder();
    		bb.append(strData);
    		return navigator.msSaveBlob(bb, strFileName);
    	} /* end if(window.MSBlobBuilder) */
    
    
    
    	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('download' in a) */
    	; //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() */

    as far as i can tell it does the same thing as downloadify, and i didn't have to wait on anything.
    if i cared about old IE support i would use ActiveX to save it via FSO.

    i will concede the filename in FF (for the next 10-16 weeks), but i don't consider that indefinitely. indefinitely is how long downloadify has to wait to work on IOS, or for those of us who use assisted technology that clickable flash widgets don't play nice with. hehe.

    why downloadify doesn't opt-in for existing HTML5 methods is a puzzle, it's probably just old code, but flash should always be a last resort on the modern web.

    if you want 100% compat, simply echo it off of a server with the right content-disposition header, a process that even works in netscape navigator.
    Last edited by rnd me; 01-20-2013 at 09:43 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  2. #17
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Flash being a last resort – true. But supporting IE, FF and Chrome still means not suppoorting several other browsers (does your function support Safari?). In the end it's probably a trade-off, there is, as of now, simply not "the perfect solution", i guess.


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •