summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cors/resources/remote-xhrer.html
blob: 73a7cb444ffb5f85a33a20de596ae33dd4f5ff8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!doctype html>
<title>Child helper</title>

<script>
window.addEventListener("message", function(e) {
//    e.source.postMessage(e.data, e.origin);

    var client = new XMLHttpRequest();
    var localurl = e.data.url
                    .replace("<host>", location.host)
                    .replace("<protocol>", location.protocol);

    client.open('GET', localurl, true);
    client.onload = function() {
        e.data.state = "load";
        e.data.response = client.response;
        e.source.postMessage(e.data, e.origin);
    }
    client.onerror = function() {
        e.data.state = "error";
        e.data.response = client.response;
        e.source.postMessage(e.data, e.origin);
    }
    client.send();
});
</script>

The remote window