【问题标题】:does not permit cross-origin framing iframe不允许跨域框架 iframe
【发布时间】:2013-11-12 05:35:45
【问题描述】:

您好,我的页面中有 2 个 iframe,其中一个工作正常,另一个无法正常工作,因为不允许跨域框架。 示例代码如下:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org   /TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="../script/jquery.js"></script>
<title>Cancellation Policy</title>
</head>
<body>

<span>Some text goes here.</span>
<br /><br />
<iframe src="http://www.w3schools.com/"></iframe>
<iframe src="https://www.google.co.in/?gws_rd=cr&ei=-bmBUo24M6npiAeepICYAg"></iframe>

</body>
</html>

任何帮助都会非常有帮助。

【问题讨论】:

  • 您希望得到什么样的帮助?你想把谷歌放在一个框架里。谷歌说他们不想要那个。你不能。还有什么好说的?

标签: jsp iframe


【解决方案1】:

嘿,我找到了问题的解决方案。 问题是因为域限制为其他域访问,因为它们可以破解此处的信息是link,它解释了跨域策略。

我们可以通过获取 html 内容并将其显示在我们的域中而不是直接访问其他域来解决这个问题。 这是link 对此进行了解释。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org   /TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script src="http://code.jquery.com/jquery-1.2.3.min.js"></script>
<title>Cancellation Policy</title>
</head>
<body>

<span>Some text goes here.</span>
<br /><br />
<iframe src="http://www.w3schools.com/"></iframe>
<iframe src="https://www.google.co.in/?gws_rd=cr&ei=-bmBUo24M6npiAeepICYAg"></iframe>

<script>
        var url = 'https://www.google.co.in/?gws_rd=cr&ei=-bmBUo24M6npiAeepICYAg';
        $.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent(url) + '&callback=?', function(data){
            var html = ""+data.contents;

            /* Replace relative links to absolute ones */
            html = html.replace(new RegExp('(href|src)="/', 'g'),  '$1="'+url+'/');

            $("#siteLoader").html(html);
        });
    </script>
    <div id="siteLoader">
        <i>Loading&hellip;</i>
    </div>
</body>
</html>

【讨论】:

  • 有可能,但问题是我们甚至无法从该页面发送任何请求或接收一些响应。
【解决方案2】:

我认为您无法在 iframe 中打开安全网站。即那些以 https:// 开头的网站无法在 iframe 中打开。您可以在 iframe 中打开 w3school.com,但不能在 iframe 中打开 https://twitter.comhttps://facebook.comhttps://google.com 等。

尝试在 iframe 中打开 google.co.in 时出现以下错误:

Load denied by X-Frame-Options: https://www.google.co.in/ does not permit cross-origin framing.

【讨论】:

  • 仅当您自己的网站是非 SSL 时才为真。
猜你喜欢
  • 2023-03-25
  • 1970-01-01
  • 2016-01-26
  • 2014-11-14
  • 2015-12-19
  • 1970-01-01
  • 2011-02-22
  • 2013-02-22
  • 1970-01-01
相关资源
最近更新 更多