tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ChildWindowPostMessage.htm (1458B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4    <title> Child window for Web Messaging tests </title>
      5 </head>
      6 <body>
      7    <script>
      8        if (window.opener)
      9        {
     10            window.onload = function()
     11            {
     12                try
     13                {
     14                    window.opener.postMessage("MSG_ONLOAD_FIRED", "*");
     15                }
     16                catch(ex)
     17                {
     18                    window.close();
     19                }
     20            }
     21        }
     22 
     23        window.onmessage = function(e)
     24        {
     25            try
     26            {
     27                if (typeof(e.data) == "object" && typeof(e.data.test) == "string")
     28                {
     29                    eval(e.data.test);
     30                }
     31                else if (e.data == "*" || e.data == "/")
     32                {
     33                    e.source.postMessage(e.data, e.data);
     34                }
     35                else
     36                {
     37                    e.source.postMessage(e.data, e.origin);
     38                }
     39 
     40                if (e.data == "ports")
     41                {
     42                    var total = e.ports.length;
     43                    for (var i=0; i<total; i++)
     44                    {
     45                        e.ports[i].onmessage = function (evt)
     46                        {
     47                            evt.target.postMessage(evt.data);
     48                        }
     49                    }
     50                }
     51            }
     52            catch(ex)
     53            {
     54            }
     55        }
     56    </script>
     57 </body>
     58 </html>