Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Real problem was that there no closing iframe tag in your localserver case, as result no javascript executed to send message. Following code works for me localy just with IPs(no domain names). </p> <p>b.html</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;meta charset="utf-8" /&gt; &lt;!-- &lt;iframe id="iframe" src="http://jsbin.com/eKUguFO/1"&gt;&lt;/iframe&gt; --&gt; &lt;iframe id="iframe" src="http://xx.xx.xx.2/web_messaging/c.html"&gt; &lt;/iframe&gt; &lt;script language="javascript" type="text/javascript"&gt; var win = document.getElementById("iframe").contentWindow; window.setTimeout(function() { win.postMessage('Hello111!!!', "http://xx.xx.xx.2"); //win.postMessage('Hello100', "http://a.test.com"); }, 2000); //win.postMessage('Hello100', "http://192.168.1.20"); &lt;/script&gt; &lt;h2&gt;WMTest - A2&lt;/h2&gt; &lt;div id="output"&gt;&lt;/div&gt; &lt;/html&gt; </code></pre> <p>c.html</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;.postMessage target&lt;/title&gt; &lt;style&gt; body { font: normal 16px/20px Helvetica, sans-serif; margin: 0; padding: 20px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;strong&gt;This iframe is located on jsbin.com (different domain)&lt;/strong&gt; &lt;p id="test"&gt;Send me a message!&lt;/p&gt; &lt;script&gt; window.onmessage = function(e){ if ( e.origin !== "http://anydomain.com" ) { //return; } document.getElementById("test").innerHTML = e.origin + " said: " + e.data; }; &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload