SHARE
TWEET

Untitled

a guest Oct 21st, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <iframe id="target-iframe" src="somepage.html"></iframe>
  2. <script>
  3.     var iframe = document.getElementById('target-iframe');
  4.     if (iframe) {
  5.         window.addEventListener('message', function (evt) {
  6.             var value;
  7.             if (evt.data.indexOf('variable:') === 0) {
  8.                 value = evt.data.replace('variable:', '');
  9.                 console.log(value); // do sth with the value
  10.             }
  11.         });
  12.         iframe.contentWindow.postMessage('getVariable', 'http://example.com')
  13.     }
  14. </script>
  15. <!-- na stronie która jest w iframe (w tym przypadku: somepage.html) -->
  16. <script>
  17.     window.addEventListener('message', function (evt) {
  18.         if (evt.data === 'getVariable' && window.parent && window.parent.postMessage) {
  19.            window.parent.postMessage('variable:' + yourVariable);
  20.         }
  21.     });
  22. </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top