Hello and welcome to our community! Is this your first visit?
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
    Thanked 626 Times in 605 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:

    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();
    		return navigator.msSaveBlob(bb, strFileName);
    	} /* end if(window.MSBlobBuilder) */
    	if ('download' in a) {
    		a.setAttribute("download", n);
    		a.innerHTML = "downloading...";
    		setTimeout(function() {
    			var e = D.createEvent("MouseEvents");
    			e.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    		}, 66);
    		return true;
    	} /* end if('download' in a) */
    	; //end if a[download]?
    	//do iframe dataURL download:
    	var f = D.createElement("iframe");
    	f.src = "data:" + (A[2] ? A[2] : "application/octet-stream") + (window.btoa ? ";base64" : "") + "," + (window.btoa ? window.btoa : escape)(strData);
    	setTimeout(function() {
    	}, 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 10:43 AM.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

  2. #17
    Regular Coder
    Join Date
    Jan 2013
    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