我想使用 iframe 在我的网站上加载另一个网站。
我在其他一些网站中使用 iframe 加载时遇到了一些其他问题。那么我们不能实现iframe来加载其他域网站页面吗?如果是这样,我们是否有其他方法来加载网站?
以下是我测试的方法:
我已经尝试过http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe使用以下代码。
<!DOCTYPE html>
<html>
<body>
<iframe src="https://github.com/mattlewis92/angular-bootstrap-calendar/issues" width="800" height="800">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
我收到以下错误。拒绝显示'https://github.com/mattlewis92/angular-bootstrap-calendar/issues https://github.com/mattlewis92/angular-bootstrap-calendar/issues' 在框架中,因为祖先违反了以下内容安全策略指令:“frame-ancestors 'none'”。
简短的回答是否定的,您不能使用 iFrame 嵌入此网站。
如果网站允许,您的代码就可以 - 但在这种情况下,您没有有效的方法来嵌入该网站。
Frame-ancestors 指令指定可以使用以下方式嵌入页面的有效父级:<frame> and <iframe>元素 https://developer.mozilla.org/en/docs/Web/Security/CSP/CSP_policy_directives#frame-ancestors
显然他们不希望您嵌入他们的网站:
服务的外观和风格版权所有 © GitHub, Inc. 保留所有权利。未经 GitHub 明确书面许可,您不得复制、复制或重复使用 HTML/CSS、Javascript 或视觉设计元素或概念的任何部分。
HOWEVER
您可以使用 javascript 来获取内容,因为他们的API https://developer.github.com/v3/允许您这样做。
尝试使用ajax来https://api.github.com/repos/mattlewis92/angular-bootstrap-calendar/issues https://api.github.com/repos/mattlewis92/angular-bootstrap-calendar/issues- 我懂了Access-Control-Allow-Origin:*
这样您就可以在 Ajax 响应中将其返回到您的页面
$(function() {
$.get("https://api.github.com/repos/mattlewis92/angular-bootstrap-calendar/issues",function(data) {
console.log(data)
$("#result").html(data[0].title);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="result"></div>
或者在您自己的服务器上使用编写代理
curl -i "https://api.github.com/repos/mattlewis92/angular-bootstrap-calendar/issues"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)