Guest User

Untitled

a guest
Jul 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. // this script exists on the *host site*
  2. const iframe = document.createElement("iframe");
  3. iframe.src = "https://us.com/iframe";
  4. parent.appendChild(iframe);
  5.  
  6. // This script exists on the *host site*
  7. function getSomeProperty()
  8. {
  9. return new Promise(function (resolve, reject)
  10. {
  11. theIFrame.postMessage("getSomeProperty", "us.com")
  12. window.addEventListener("message", function (event)
  13. {
  14. // ... get the response, making sure its from us.com, etc.
  15. // This is just pseudo code, we don't create a new listener
  16. // on every call in our real code.
  17. resolve(answer);
  18. }
  19. });
  20. }
  21.  
  22. const parent = window.parent;
  23.  
  24. // This event handler is in the *embedded iframe*
  25. window.addEventListener("message", function (event)
  26. {
  27. // This is being sent from a window other than
  28. // the one that created us, bail!
  29. if (event.window !== parent)
  30. return;
  31.  
  32. // it is safe to respond...
  33. }
  34.  
  35. const iframe = document.createElement("iframe");
  36. iframe.src = `https://us.com/iframe?location=${window.location.href}`;
Add Comment
Please, Sign In to add comment