不允许跨源框架 iframe



嗨,我 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>

任何帮助都是非常有帮助的。

嘿,

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

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

<%@ 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>

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

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

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

相关内容

最新更新