Created
November 13, 2013 16:51
-
-
Save zhannes/7452354 to your computer and use it in GitHub Desktop.
iframe form
This file contains 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
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