UNPKG

@financial-times/o-ads

Version:

This package contains the core functionality used by the FT in providing ads across all of its sites. This includes ft.com, howtospendit.com, ftadviser.com and other specialist titles.

30 lines (26 loc) 677 B
/** * Utility methods for postMessage api. * @author Origami Advertising, origami.advertising@ft.com * @module utils */ export default { post: function(message, source) { message = typeof message === 'string' ? message : JSON.stringify(message); source = arguments[1] || window.top; source.postMessage(message, '*'); }, parse: function(message) { // Check whether the message looks like an object before trying to parse it if (typeof message !== 'string' || message[0] !== '{') { return message; } // try returning the parsed object try { return JSON.parse(message); } // return the original message catch(e){ return message; } } };