post to iframe parent

In this example below you will see how to do a post to iframe parent with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by postor, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright postor ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>post to iframe parent</title>
  
  
  
  
  
</head>

<body>

  
<table>
  <tr>
    <td>1a</td>
    <td>1b</td>
    <td>1c</td>
  </tr>
  <tr>
    <td>2a</td>
    <td>2b</td>
    <td>2c</td>
  </tr>
  <tr>
    <td>3a</td>
    <td>3b</td>
    <td>3c</td>
  </tr>
</table>
<iframe src="https://s.codepen.io/postor/debug/goxBWR/jVkpogOpjReA"></iframe>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/postor/post-to-iframe-parent-RxZeVK */
$(() => {
  const iframe = $("iframe")[0];
  $("td").click(function() {
    iframe.contentWindow.postMessage($(this).text(),'*');
  });
});

Comments