function sendMessageToParentWindow(typeOfMessage, message = null) { let postMessage = { bordeaux: message }; let url = " love winter.html"; if (typeOfMessage === "analytics") { postMessage = { analytics: { ...message } }; } if (postMessage !== {}) { window.parent.postMessage( postMessage, url ); } } let message = { targeting: { ["express love winter.html"]: "" } } window.onload = sendMessageToParentWindow("bordeaux", message); Source: WhoWhatWear