javascript DOMException:阻止了来源为“http://localhost”的框架访问跨源框架

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51817773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 09:42:22  来源:igfitidea点击:

DOMException: Blocked a frame with origin "http://localhost" from accessing a cross-origin frame

javascriptasp.net-mvcgwt

提问by DeveloperSD

I have two web application on different domain.

我在不同的域上有两个 Web 应用程序。

  1. Web App1
  2. Web App2
  1. 网络应用1
  2. 网络应用程序2

My Final goal is as par below.

我的最终目标如下。

enter image description here

在此处输入图片说明

I have found the tutorial to login with Google account API in Asp.net MVC - 5.

我在 Asp.net MVC - 5 中找到了使用 Google 帐户 API 登录的教程。

https://tutorialslink.com/Articles/How-to-login-with-Google-account-API-in-Aspnet-MVC---5/18

https://tutorialslink.com/Articles/How-to-login-with-Google-account-API-in-Aspnet-MVC---5/18

By using same concept I am trying to do below things

通过使用相同的概念,我正在尝试做以下事情

  1. Open WebApp2 from WebApp1

  2. From WebApp2 on Apply event redirect to specified URL consist of URL + required data in encrypted format.

  3. From WebApp1 by continuously checking for the updated URL and accordingly display the data on WebAp1.

  4. Close the WebApp2.
  1. 从 WebApp1 打开 WebApp2

  2. 从 WebApp2 应用事件重定向到指定的 URL 由 URL + 加密格式的所需数据组成。

  3. 从 WebApp1 不断检查更新的 URL 并相应地在 WebAp1 上显示数据。

  4. 关闭 WebApp2。

To achieve the above steps, my source code (WebApp1) as par below.

为了实现上述步骤,我的源代码(WebApp1)如下。

var REDIRECT = "http://localhost/Home/Test";
var webApp2 = window.open("WebApp2Url", "CrossDomain", '', true);

var pollTimer = window.setInterval(function () {
try {
    if (webApp2.document.URL.indexOf(REDIRECT) != -1) {
    window.clearInterval(pollTimer);
    // logic to retrieve data from webApp2.document.URL
    webApp2.close();
    debugger;
    }
}
catch (e) {
}
}, 500);

I am getting below error at code line

我在代码行遇到以下错误

[if (webApp2.document.URL.indexOf(REDIRECT) != -1) {]

DOMException: Blocked a frame with origin "http://localhost" from accessing a cross-origin frame.

DOMException: 阻止了源为“ http://localhost”的框架访问跨源框架。

Please any one can guide me to resolve above error.

请任何人都可以指导我解决上述错误。

I have tried with enabling CORS in WebApp2 but it didn't work.

我曾尝试在 WebApp2 中启用 CORS,但没有奏效。

Any idea to design WebApp2 is highly welcome.

任何设计 WebApp2 的想法都非常受欢迎。

采纳答案by DeveloperSD

I have got the work around for the same.

我有同样的工作。

In my WebApp2 After finishing with processing I am redirect control to my WebApp1 i.e to domain1.

在我的 WebApp2 完成处理后,我将控制重定向到我的 WebApp1,即 domain1。

Reference:

参考:

How do I get around window.opener cross-domain security

我如何绕过 window.opener 跨域安全