Created
September 25, 2011 09:39
-
-
Save lepture/1240424 to your computer and use it in GitHub Desktop.
iframe uploader
This file contains hidden or 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
/* | |
* @require jquery.js | |
* @author lepture | |
*/ | |
if(window.jQuery){(function($){ | |
var iframeUploader = function(options) { | |
var settings = { | |
'iframeID': 'ifrUploader', | |
'callback': null | |
} | |
if (options) { | |
$.extend(settings, options) | |
} | |
$(this).submit(function(){ | |
$(this).attr('target', 'iframeUploader'); | |
var iframeHTML = '<iframe id="' + settings.iframeID + '" name="iframeUploader" style="display:none"></iframe>'; | |
$('body').append(iframeHTML); | |
var iframe = $('#' + settings.iframeID).load(function(){ | |
var response = iframe.contents().find('body').html(); | |
if (settings.callback) { | |
settings.callback(response) | |
} | |
$(iframe).unbind('load'); | |
iframe.remove(); | |
}); | |
return true; | |
}); | |
} | |
$.extend($.fn, { | |
iframeUploader: iframeUploader | |
}); | |
})(jQuery);} | |
/* test */ | |
$(function(){ | |
function callback(response) { | |
$('body').append(response); | |
} | |
$('form').iframeUploader({ | |
'callback': callback | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment