使用其他域访问iFrame [英] Access iFrame with a different domain

查看:627
本文介绍了使用其他域访问iFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在推出一个2帧的网站,其中一个包含google.com,另一个包含localhost应用程序



这是我在谷歌控制台中的错误:



不安全的JavaScript尝试使用URL'http://启动框架导航localhost:5199 / default.aspx'来自网址https://www.google.co.in。尝试导航的帧既不是目标的同源,也不是目标的父或开启者。



未捕获的安全错误:阻止了一个原始帧http:/ /google.co.in访问带有原点的框架http:// localhost:5199。协议,域名和端口必须匹配。



有人可以帮我解决这个错误



在此先感谢。

Hi,

I'm craeting a website with 2 frames,one of them contains google.com and other with localhost application

This is the error im getting in Google console:

Unsafe JavaScript attempt to initiate navigation for frame with URL 'http://localhost:5199/default.aspx' from frame with URL 'https://www.google.co.in'. The frame attempting navigation is neither same-origin with the target, nor is it the target's parent or opener.

Uncaught SecurityError: Blocked a frame with origin "http://google.co.in" from accessing a frame with origin "http://localhost:5199". Protocols, domains, and ports must match.

Can someone help me how to solve this error

Thanks in advance.

推荐答案

您还可以通过在Global.asax文件中添加此代码来修复CORS原始请求错误。



You can also fix the CORS origin request error by adding this code in Global.asax file.

protected void Application_BeginRequest(object sender, EventArgs e)
        {

            // enable CORS
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "https://www.google.co.in");

        }


这篇关于使用其他域访问iFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆