如何在Angle 7中使用iframe

时间:2019-10-11 04:12:40

标签: angular

我正在使用iframe通过以下方法在HTML中设置外部网址:

方法1:

#include <iostream> 

using namespace std;

int main()

{
    int rows, count, num, space;//creating four variables to use for the loops

    cout << "Enter number of rows: ";//prompting the user to input the number of rows
    cin >> rows;

    while (rows < 1 || rows>9)
    {
        cout << "Entry must be between 1 and 9. Please Re-enter the number of rows" << endl; //Asking the user to re-enter the number of rows if it was an invalid input
        cin >> rows;
    }

    for (count = 1; count <= rows; count++) //for function that loops from 1-how many rows the user puts in
    {
        for (space= 1; space < rows; space++) //inner loop that loops from 1 to how many rows the user put in and outputs a space
        {
            cout << "  ";
        }

        for (num = 1; num <= (2*count-1); num++)//the last row of the pyramid has one less than two time sthe number the user input so this loops unitl that is hit
        {
            cout <<count << " ";
        }
        cout << "\n"; //outputs a new line 

    }
    system("pause");
    return 0;
}

方法2:在此方法中,我还使用How to set <iframe src="..."> without causing `unsafe value` exception?

创建了一个安全PIPE
 <iframe [src]="sanitizer.bypassSecurityTrustResourceUrl(srcUrl)" height="600" width="1000"></iframe>

方法3:

 <iframe width="100%" height="300" [src]="srcUrl | safe"></iframe>

但是没有人为我工作。我遇到以下错误:

拒绝在框架中显示”,因为祖先违反了以下内容安全策略指令:“ frame-ancestors'self'”。

请在下面的链接中找到我的代码:

https://stackblitz.com/edit/angular-irwasj?file=src%2Fapp%2Fapp.component.html 谁能帮忙吗?

1 个答案:

答案 0 :(得分:2)

我正在调查这个。很少有网站如google,stackoverflow,youtube拒绝在iframe中加载。它使用某种FrameKiller。如果您使用https://www.google.com,它将显示google.com拒绝连接。其他站点,例如stackoverflow根本不显示任何消息。我为此创建了一个演示,并使用https加载了其他随机站点。

演示:https://stackblitz.com/edit/angular-gzvckb