title: How to execute a function through postMessage
body: <p>I have this code inside a iframe:</p>
  
  <pre><code>window.addEventListener('message', function(e){
  
    if(e.data == 'test')
      console.log(e);
  
  }, false);
  </code></pre>
  
  <p>and this inside the parent document:</p>
  
  <pre><code>$('#the_iframe').get(0).contentWindow.postMessage('test', 'http://localhost/');
  </code></pre>
  
  <p>So the parent document sends a "test" message to the iframe and it works.</p>
  
  <p>But how can I define a function in the parent document, and somehow send this function through postMessage to the iframe, which will execute the function locally?</p>
  
  <p>The function does some changes to the document like this:</p>
  
  <pre><code>var func = function(){
    $("#some_div").addClass('sss');
  }
  </code></pre>
  
  <p>(<code>#some_div</code> exists in the iframe, not the parent document)</p>