我在我的 angular2 v4 应用程序中得到了这个:
<iframe src="https://www.w3schools.com" style="width: 100%; height: 500px"></iframe>
但它不起作用。我怎样才能做到这一点?我尝试使用 |安全
,但它也不起作用。请帮忙
最佳答案
如果您查看控制台,您可能会看到以下消息:
Refused to display 'https://www.w3schools.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
X-Frame-Options
header 允许网站阻止具有不同来源(域)的网站在<iframe/>
内使用它们。 。这基本上意味着只有 www.w3schools.com
上托管的页面可以在 <iframe/>
中使用该 url来源。 You can read more about it here .
你的代码(你忽略了所以分享了很多)在语法上很可能是好的。您可以尝试另一个网址 <iframe/>
.
关于javascript - 如何在 Angular4 中设置 iframe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49762504/