You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
837 B
JavaScript
33 lines
837 B
JavaScript
7 years ago
|
var validDomains = [ /.*/i, ];
|
||
|
var isValidDomain = function (o) {
|
||
|
return validDomains.some(function (e) {
|
||
|
switch (typeof(e)) {
|
||
|
case 'string': return e === o;
|
||
|
case 'object': return e.test(o);
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
window.addEventListener('message', function(e) {
|
||
|
if (!isValidDomain(e.origin)) { return; }
|
||
|
var payload = JSON.parse(e.data);
|
||
|
var parent = window.parent;
|
||
|
var respond = function (error, data) {
|
||
|
var res = {
|
||
|
_uid: payload._uid,
|
||
|
error: error,
|
||
|
data: data,
|
||
|
};
|
||
|
parent.postMessage(JSON.stringify(res), '*');
|
||
|
};
|
||
|
|
||
|
//console.error(payload);
|
||
|
switch(payload.method) {
|
||
|
case undefined:
|
||
|
return respond('No method supplied');
|
||
|
default:
|
||
|
return respond(void 0, "EHLO");
|
||
|
}
|
||
|
});
|
||
|
|