Created
July 25, 2013 02:04
-
-
Save PatrickJS/6076326 to your computer and use it in GitHub Desktop.
old Cross Origin with iFrame and jQuery
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
| $(function($) { | |
| if ($.xdomPost) { return; } | |
| var ifc = +new Date(), | |
| css = { position: 'absolute', top: '-1000px', left: '-1000px'}, | |
| ieop = $.browser.msie || $.browser.opera && window.opera.version() < 9; | |
| $.xdomPost = function(url, data, options) { | |
| var opts = $.extend({appendTo: 'body'}, options); | |
| var inputs = '', | |
| ifr = 'ifr' + ifc++, | |
| iid = 'xdom' + ifr, | |
| fid = 'form' + ifr, | |
| $iframe = $('<iframe></iframe>', { | |
| id: iid, | |
| name: iid, | |
| css: css | |
| }), | |
| $form = $('<form></form>', { | |
| id: fid, | |
| name: fid, | |
| action: url, | |
| target: iid, | |
| css: css, | |
| method: 'POST' | |
| }); | |
| if ( ieop ) { | |
| $iframe[0].src = 'javascript:false;document.write("");'; | |
| } | |
| $.each(data, function(key, value) { | |
| inputs += '<input name="' + key + '" value="' + value + '">'; | |
| }); | |
| $iframe.appendTo(opts.appendTo); | |
| $form.append('<fieldset>' + inputs + '</fieldset>').appendTo(opts.appendTo); | |
| $form[0].submit(); | |
| }; | |
| }(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment