sending data from local context to web context (WINJS)

612 Views Asked by At

I have a program where i have a page in the local context and within this page i have got an iframe where the content of it is in the web context. Now I would like to send some data from the local context to the web context. How do i do this.

local

var node = document.createElement("iframe");
node.src = 'ms-appx-web:///pages/mapView/mapView.html?latitude=' + coordinates.latitude + '&longitude=' + coordinates.longitude;
node.style.width = '100%';
node.style.height = '100%';
node.onload = function () {
    node.contentWindow.postMessage(JSON.stringify(data), "ms-wwa-web://" + 
                                   document.location.host);
}
document.querySelector('#insert').appendChild(node);

in the iframe i do:

window.addEventListener('message', receiveMsg, false);

I have got an ajax call where i got some data, but because i have no access to ajax calls in web context i would like to send some data from this here to mapView.html.

The problem is. I would send some values via Get Parameter, but I have too much data for that.

any help?

1

There are 1 best solutions below

0
GotDibbs On BEST ANSWER

Try switching this line:

node.contentWindow.postMessage(JSON.stringify(data), "ms-wwa-web://" + 
                               document.location.host);

... to this:

node.contentWindow.postMessage(JSON.stringify(data), "*");

If that works, you should be ok doing that here in a Win 8 app (wouldn't do that in a web app for security reasons), but if you want to lock it down more I think you'd just need to change the second parameter to be one of:

  • "ms-www-web:///" (note the triple slash)
  • "ms-www-web:///pages/"