Javascript Can';无法使iframe.contentwindow/postmessage正常工作,因为同一域内的权限被拒绝
我无法使用最简单的iframe contentwindow代码,因为对contentwindow的权限总是被拒绝。在使用我自己的代码进入WTF阶段后,我将我的尝试隔离开来,在下面的示例中,我仅使用Microsoft自己的示例代码,这些代码来自MSDN帮助中的iframe contentwindow文档。MSDN的代码也有同样的问题!(实际上它有两个问题,但我修复了它对iframe的用法,因为iframe!=“iframe”。) 我正在Visual Studio Community 2015中使用Javascript Windows 8-Windows模板进行开发 在调试过程中,我发现每当我使用iframeid.contentwindow构造时,我都会被拒绝权限,如本文末尾的屏幕截图所示 这是我的密码: 1) default.html:(直接从文档中粘贴到VS中) 尽管找到了几篇看似相似的帖子,但我没有发现任何有用的东西。许多帖子讨论了AJAX、跨域起源、CORS、iFrame的浏览器支持…——我一点也不复杂。我现在只在VS debugger中运行此代码,并打算以这种方式将代码用作一层本地应用程序或部署用于本地IIS/Chrome。我有一种感觉,要么永远不可能访问iframe的contentwindow,要么我错过了一些简单的东西。我怀疑是后者。如果你知道答案,我将非常感谢你的帮助 谢谢Javascript Can';无法使iframe.contentwindow/postmessage正常工作,因为同一域内的权限被拒绝,javascript,visual-studio,iframe,msdn,postmessage,Javascript,Visual Studio,Iframe,Msdn,Postmessage,我无法使用最简单的iframe contentwindow代码,因为对contentwindow的权限总是被拒绝。在使用我自己的代码进入WTF阶段后,我将我的尝试隔离开来,在下面的示例中,我仅使用Microsoft自己的示例代码,这些代码来自MSDN帮助中的iframe contentwindow文档。MSDN的代码也有同样的问题!(实际上它有两个问题,但我修复了它对iframe的用法,因为iframe!=“iframe”。) 我正在Visual Studio Community 2015中使用
你最终成功了吗?你最终成功了吗?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>App3</title>
<!-- WinJS references -->
<link href="//Microsoft.WinJS.2.0/css/ui-dark.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.2.0/js/base.js"></script>
<script src="//Microsoft.WinJS.2.0/js/ui.js"></script>
<!-- App3 references -- >
<link href="/css/default.css" rel="stylesheet" />
<script type="text/javascript">
function fnNavigate() {
for (i = 0; i < document.all.length; i++) {
if (document.all(i).tagName == "IFRAME") {
document.all(i).contentWindow.location = "http://www.msn.com";
}
}
}
</script>
<script src="/js/default.js"></script>
</head>
<body>
<p> start
<button onclick="fnNavigate();">Navigate Frames</button>
<p>
<iframe src="http://www.microsoft.com" style="width:100%;height:150px;"> </iframe>
<p />
<iframe src="http://www.microsoft.com" style="width:100%;height:150px;"></iframe>
<p />
<iframe src="http://www.microsoft.com" style="width:100%;height:150px;"></iframe>
<p /> end
</body>
</html>
(function () {
"use strict";
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// TODO: This application has been newly launched. Initialize
// your application here.
} else {
// TODO: This application was suspended and then terminated.
// To create a smooth user experience, restore application state here so that it looks like the app never stopped running.
}
args.setPromise(WinJS.UI.processAll());
}
};
app.oncheckpoint = function (args) {
// TODO: This application is about to be suspended. Save any state
// that needs to persist across suspensions here. You might use the
// WinJS.Application.sessionState object, which is automatically
// saved and restored across suspension. If you need to complete an
// asynchronous operation before your application is suspended, call
// args.setPromise().
};
app.start();
})();