Windows应用商店应用程序和iFrame cookie
Windows Store App and iFrame cookie
我有一个托管iframe的Javascript Windows Store应用程序。我的iframe中的网页不知道我的应用程序,所以它没有任何PostMessage
接口。
当我"登录"iframe时,iframe会设置一个cookie。但在我的应用程序中,我不相信有什么方法可以获得iframe cookie。这是正确的吗?
如果网页知道我的申请怎么办?(即,我可以更改iframe中的网页)我是否使用PostMessage?
您可以使用PostMessage,您的主页面将收到消息。
以下是Win8开发者预览版中的工作示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=1024, height=768" />
<title>WinWebApp1</title>
<!-- WinJS references -->
<link rel="stylesheet" href="/winjs/css/ui-dark.css" />
<script src="/winjs/js/base.js"></script>
<script src="/winjs/js/wwaapp.js"></script>
<script src="/winjs/js/ui.js"></script>
<!-- WinWebApp3 references -->
<link rel="stylesheet" href="/css/default.css" />
<script src="/js/default.js"></script>
<script type="text/javascript">
window.attachEvent("onmessage", receiveMessage);
function receiveMessage(e) {
if (e.origin == "http://www.scrumpt.com")
document.getElementById("target-element-id").innerHTML = e.data;
}
</script>
</head>
<body>
<iframe src="http://www.scrumpt.com/frametest2.html" style="display: block; width: 699px; height: 296.95px; left: -499px; top: 0px;"></iframe>
<div data-win-control="WinJS.UI.ViewBox" style="display: block; top: 50%;">
<div class="fixed-layout">
<div id="target-element-id">Click on Send Message above</div>
</div>
</div>
</body>
</html>
在服务器上(目前正在运行http://www.scrumpt.com/frametest2.html)你有:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function send() {
parent.postMessage('hello world', '*');
}
</script>
</head>
<body>
<a href="javascript:send()">Send message</a>
</body>
</html>
如果复制粘贴上面的代码,请确保div("targetelementid")具有正确的id。VS可能会在粘贴时将id更改为"Div1"。
相关文章:
- 防止Iframe窗体在新窗口中打开
- 将样式表插入iframe
- Cross protocol cookie iFrame
- 使用 Iframe 问题设置跨域 Cookie
- 是否可以在没有 Cookie 数据的情况下创建 iframe
- Cookie 设置为 iframe javascript 中的父窗口
- JavaScript set cookie via iFrame via CORS via PHP Allow Head
- 使用没有会话或 Cookie 数据的 iFrame(无痕)
- 如何在javascript中读取显示在iframe中的外部网站的cookie
- 无法通过iframe添加cookie
- 如何在 iframe 中设置 cookie?Facebook Cookie 的工作原理
- Windows应用商店应用程序和iFrame cookie
- 删除按Iframe设置的已有Cookie
- 在iframe内执行alert(document.cookie)
- Read IFrame cookie
- 通过文档.从独立域的iframe内将Cookie转换为PHP
- 无法访问在iframe中加载的自己域上的httponly标记的cookie
- 如何在设置iframe时将cookie附加到请求中.SRC(使用jquery)
- Cookie在安卓Webview的iframe中不起作用
- Iframe不能读取或设置cookie