Skip to content

Instantly share code, notes, and snippets.

@zhannes
Created November 13, 2013 16:51
Show Gist options
  • Save zhannes/7452354 to your computer and use it in GitHub Desktop.
Save zhannes/7452354 to your computer and use it in GitHub Desktop.
iframe form
function iFramePost(form){
if(!form) return;
if(!form.jquery) form = $(form);
var f = document.createElement('iframe');
var target = 'iframe_target_' + (new Date).getTime();
form.attr('target',target);
f.name = target;
var id = 'iframe_post_' + (new Date).getTime();
f.id = id;
form.attr('data-iframe-post-id',id);
f.style.display = 'none';
f.src = form.attr('action');
document.body.appendChild(f);
// ?? delay, so it doesn't fire when added to DOM
setTimeout(function(){
f.onload = function(e){
f.parentElement.removeChild(f);
};
},3000);
}
function submitAsiFrame(n,form){
if(!form) return;
iFramePost(form);
$(form).on('click','[type="submit"]',function(){
// handle UI, show success, whatever
});
}
$('[data-some-form-selector]').each(submitAsiFrame);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment