4 * jQuery File Upload Plugin postMessage API
5 * https://github.com/blueimp/jQuery-File-Upload
7 * Copyright 2011, Sebastian Tschan
10 * Licensed under the MIT license:
11 * https://opensource.org/licenses/MIT
16 <meta charset="utf-8" />
17 <title>jQuery File Upload Plugin postMessage API</title>
19 src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"
20 integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ"
21 crossorigin="anonymous"
27 var origin = /^https:\/\/example.org/,
28 target = new RegExp('^(http(s)?:)?\\/\\/' + location.host + '\\/');
29 $(window).on('message', function (e) {
32 xhr = $.ajaxSettings.xhr(),
34 if (!origin.test(e.origin)) {
35 throw new Error('Origin "' + e.origin + '" does not match ' + origin);
37 if (!target.test(e.data.url)) {
39 'Target "' + e.data.url + '" does not match ' + target
42 $(xhr.upload).on('progress', function (ev) {
43 ev = ev.originalEvent;
48 timeStamp: ev.timeStamp,
49 lengthComputable: ev.lengthComputable,
59 if (!(s.data instanceof Blob)) {
61 $.each(s.data, function (i, v) {
62 f.append(v.name, v.value);
66 $.ajax(s).always(function (result, statusText, jqXHR) {
75 statusText: statusText,
77 headers: jqXHR.getAllResponseHeaders()