Skip to content Skip to sidebar Skip to footer

Windows Store App And Iframe Cookie

I have a Javascript Windows Store Application that hosts an iframe. The webpage inside of my iframe is not aware of my app, so it doesn't have any PostMessage interface to my app.

Solution 1:

You can use PostMessage that your main page will receive the message.

Here is working example in Win8 Developer Preview:

<!DOCTYPE html><html><head><metacharset="utf-8" /><metaname="viewport"content="width=1024, height=768" /><title>WinWebApp1</title><!-- WinJS references --><linkhref="/winjs/css/ui-dark.css" /><scriptsrc="/winjs/js/base.js"></script><scriptsrc="/winjs/js/wwaapp.js"></script><scriptsrc="/winjs/js/ui.js"></script><!-- WinWebApp3 references --><linkhref="/css/default.css" /><scriptsrc="/js/default.js"></script><scripttype="text/javascript">window.attachEvent("onmessage", receiveMessage);

            functionreceiveMessage(e) {
                if (e.origin == "http://www.scrumpt.com")
                    document.getElementById("target-element-id").innerHTML = e.data;

            }
</script></head><body><iframesrc="http://www.scrumpt.com/frametest2.html"style="display: block; width: 699px; height: 296.95px; left: -499px; top: 0px;"></iframe><divdata-win-control="WinJS.UI.ViewBox"style="display: block; top: 50%;"><divclass="fixed-layout"><divid="target-element-id">Click on Send Message above</div></div></div></body></html>

On the server (it is live at this moment on http://www.scrumpt.com/frametest2.html) you have:

<!DOCTYPE html><html><head><scripttype="text/javascript">functionsend() {
      parent.postMessage('hello world', '*');
}
</script></head><body><ahref="javascript:send()">Send message</a></body></html>

make sure that your div ("target-element-id") has the correct id when if you copy paste the code above. VS might change the id to "Div1" when pasting.

Post a Comment for "Windows Store App And Iframe Cookie"