Skip to content

Instantly share code, notes, and snippets.

@lepture
Created September 25, 2011 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lepture/1240424 to your computer and use it in GitHub Desktop.
Save lepture/1240424 to your computer and use it in GitHub Desktop.
iframe uploader
/*
* @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