Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this script exists on the *host site*
- const iframe = document.createElement("iframe");
- iframe.src = "https://us.com/iframe";
- parent.appendChild(iframe);
- // This script exists on the *host site*
- function getSomeProperty()
- {
- return new Promise(function (resolve, reject)
- {
- theIFrame.postMessage("getSomeProperty", "us.com")
- window.addEventListener("message", function (event)
- {
- // ... get the response, making sure its from us.com, etc.
- // This is just pseudo code, we don't create a new listener
- // on every call in our real code.
- resolve(answer);
- }
- });
- }
- const parent = window.parent;
- // This event handler is in the *embedded iframe*
- window.addEventListener("message", function (event)
- {
- // This is being sent from a window other than
- // the one that created us, bail!
- if (event.window !== parent)
- return;
- // it is safe to respond...
- }
- const iframe = document.createElement("iframe");
- iframe.src = `https://us.com/iframe?location=${window.location.href}`;
Add Comment
Please, Sign In to add comment