[RESOLVED]get page from Worker

On page of example.com I have this code

<area shape='rect' coords='84,84,293,111' onclick='go()'>"

In main js file I have

var pages = {};
var loader = new Worker("http://sub1.example.com/w_p.js");
loader.onmessage = function (e) {
    pages = e.data;
function go()
    doc.getElementById(contentContainer).innerHTML = pages[0];

In the worker file w_p.js

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://sub2.example.com/", false);
var pages = {};
pages[0] = xhr.responseText;

When I click on go() link I see only undefined in container. What’s wrong?

You’re trying to asynchronously load the Google home page? You’ll get a Crooss Origin error if you try to do that (unless you’re actually working on the Google website which I assume you’re not).

You can only load content from your own domain unless you use JSONP or the server you’re requesting the content from has allowed cross origin resource sharing.

Server allowed CORS. I use Google as example. Give simple right code example, please.


  You can check to see if the worker javascript is downloading by using the developers tools of the browser (Press F12- Network monitor). If you get a 404, you need to update the path in this call:

new Worker("w_p.js");

hope that helps.

Thank you.

Previous path wrong, but new call security problem:

SecurityError: The operation is insecure.

var loader = new Worker("http://sub1.example.com/w_p.js");

downloads scripts
1, in which
a worker is working,
trying to make an asynchronous request
to the subdomain
I changed the code
in the first message
to be closer
to reality.

Hi Alex,


Previous path wrong, but new call security problem:

SecurityError: The operation is insecure.

As for your problem, you should follow the
Same Origin Policy
. This means same domain, same subdomain, same protocol (http vs https) and same port. Here is a similar issue, you could refer to it.

Hope it will be helpful to you.

Best Regards,


Leave a Reply