function bindEvent(element, eventName, eventHandler) { if (element.addEventListener){ element.addEventListener(eventName, eventHandler, false); } else if (element.attachEvent) { element.attachEvent('on' + eventName, eventHandler); } }
// Listen to message from child window bindEvent(window, 'message', receiveMessage);
function receiveMessage(e) { if (typeof e.data == 'string' && e.data != "" && e.data.charAt(0) == '{') { try { var args = JSON.parse(e.data); if (!args.__postRobot__) { childObj = eval(args.vars); console.log(childObj); console.log(args.method); eval(args.method + "(childObj)"); } } catch (error){ // Do nothing } } }