问题一、 iframe如何自适应屏幕高度

解决思路:通过设置iframe外层父元素高度等于window高度,再相对于父元素定位iframe元素;案例如下:

第一步: 模板文件中使用iframe


// demo.component.html
<div style="position: relative; " [style.height]="outHeight">
<iframe [src]="srcValue" allowtransparency="true" frameborder="0" id="defaulIframePage" style="position: absolute; width: 100%; height: 100%; "></iframe>
</div>

第二步: ts 中自定义iframe外层父元素的高度


// demo.component.ts
import {fromEvent} from "rxjs/index"; export class DemoComponent imple implements OnInit{ srcValue = 'http://www.baidu.com';
outHeight = '0px'; ngOnInit() {
// ifram最外层高度
this.outHeight = window.innerHeight + 'px';
fromEvent(window, 'resize').subscribe(($event) => {
this.outHeight = window.innerHeight + 'px';
});
}
}

问题二、 安全机制设置

错误:

解决:

第一步:创建管道


import { Pipe, PipeTransform } from '@angular/core';
import {DomSanitizer} from "@angular/platform-browser"; @Pipe({
name: 'safe'
})
export class SafePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
transform(value: any, args?: any): any {
return this.sanitizer.bypassSecurityTrustResourceUrl(value);
}
}

第二步: 在demo.component.html文件中加入管道


<iframe [src]="item.url | safe" allowtransparency="true" frameborder="0" id="defaulIframePage" style="position: absolute; width: 100%; height: 100%; "></iframe>

问题三、src值为同域名不同参数时,iframe不刷新问题

解决思路:使用动态组件 - 将iframe放至动态组件中,父组件将src传值给动态组件,并且每次传值时动态渲染组件;

1. 父组件定义


// parent.component.html
<a href= "javascript:;" (click)="loadCmp(srcArray[1])">切换iframe的src值</a>
<div #dynamic></div> // parent.component.ts
export class ParentComponentimplements OnInit, OnDestroy { // 动态切换的src模拟数据
srcArray = ["index.html?id='11'", "index.html?id='22'"]; // 动态组件
@ViewChild('dynamic', { read: ViewContainerRef }) dmRoom: ViewContainerRef;
currentCmp: any; // 当前渲染组件 constructor(private cfr: ComponentFactoryResolver) {} ngOnInit() {
// 动态渲染组件
this.loadCmp(this.srcArray[0]);
} // 动态渲染组件方法
loadCmp(srcValue) { const com = this.cfr.resolveComponentFactory(DynamicComponent);
this.dmRoom.clear(); // 清空视图
this.currentCmp = this.dmRoom.createComponent(com); // 传值
this.currentCmp.instance.pathUrl = srcUrl; }
}

2. 动态组件定义


// dynamic组件;;别忘记将DynamicComponent加入数组entryComponents中;
// dynamic.component.html
<iframe [src]="pathUrl | safe" allowtransparency="true" frameborder="0" id="defaulIframePage" style="position: absolute; width: 100%; height: 100%; "></iframe> // dynamic.component.ts
export class DynamicComponent {
pathUrl: string = '';
}

angular6 iframe应用的更多相关文章

  1. 完美判断iframe是否加载完成

    var iframe = document.createElement("iframe"); iframe.style.width = "265px"; ifr ...

  2. js学习笔记:操作iframe

    iframe可以说是比较老得话题了,而且网上也基本上在说少用iframe,其原因大致为:堵塞页面加载.安全问题.兼容性问题.搜索引擎抓取不到等等,不过相对于这些缺点,iframe的优点更牛,跨域请求. ...

  3. 页面嵌入dom与被嵌入iframe的攻防

    1.情景一:自己的页面被引入(嵌入)至别人的页面iframe中 if(window.self != window.top){ //url是自己页面的url window.top.location.hr ...

  4. iframe用法

    <iframe src="http://caiyanli.top/" height="500"  width="500" frameb ...

  5. 如何获取url中的参数并传递给iframe中的报表

    在使用报表软件时,用户系统左边一般有目录树,点击报表节点就会在右侧网页的iframe中显示出报表,同时点击的时候也会传递一些参数给网页,比如时间和用户信息等.如何使网页中的报表能够获取到传递过来的参数 ...

  6. JavaScript权威设计--Window对象之Iframe(简要学习笔记十四)

    1.Window对象属性的文档元素(id) 如果在HTML文档中用id属性来为元素命名,并且如果Window对象没有此名字的属性,Window对象会赋予一个属性,它的名字是id属性的值,而他们的值指向 ...

  7. ASP.NET 页面禁止被 iframe 框架引用

    两个站点: a.sample.com b.sample.com a.sample.com 站点中的一段示例 JS 代码: var iframe = document.createElement(&qu ...

  8. 父页面操作iframe子页面的安全漏洞及跨域限制问题

    一.父子交互的跨域限制 同域情况下,父页面和子页面可以通过iframe.contentDocument或者parent.document来交互(彼此做DOM操作等,如父页面往子页面注入css). 跨域 ...

  9. 解决iframe作为子窗口,刷新后iframe页面跳转到其它页面的问题

    转载请在页首注明作者与出处 http://www.cnblogs.com/zhuxiaojie/p/5990262.html 前言: 在开发网站时,尤其是管理后台,我们经常会使用iframe作为内容窗 ...

随机推荐

  1. 一 安装docker(详解)

    一.安装docker 1 Docker 要求 CentOS 系统的内核版本高于 3.10 执行命令:uname -r 2 添加yum源: yum-config-manager --add-repo h ...

  2. ElementUI使用v-if控制tab标签显示遇到的Duplicate keys detected: 'xxx'问题

    今天工作遇到一个问题: 需求背景:页面中有几个tab,需要根据登录用户的权限控制tab标签的显示与隐藏 . <el-tabs @tab-click="handleClick" ...

  3. CodeForces - 697C-Lorenzo Von Matterhorn(有点像LCA,原创

    传送门: CodeForces - 697C 原创--原创--原创 第一次自己A了一道感觉有点难度的题: 题意:在一个类似于二叉树的图上,1 : u ,v,w 表示从u到v的所以路都加上w的费用: 2 ...

  4. 三个小白是如何在三个月内搭一个基于kaldi的嵌入式在线语音识别系统的

    前面的博客里说过最近几个月我从传统语音(语音通信)切到了智能语音(语音识别).刚开始是学语音识别领域的基础知识,学了后把自己学到的写了PPT给组内同学做了presentation(语音识别传统方法(G ...

  5. [DP]换钱的方法数

    题目三 给定数组arr, arr中所有的值都为整数且不重复.每个值代表一种面值的货币,每种面值的货币可以使用任意张,在给定一个整数aim代表要找的钱数,求换钱有多少种方法. 解法一 --暴力递归 用0 ...

  6. centos 6.5 搭建DHCP实验

    搭建DHCP服务 安装DHCP服务 挂载光盘:mount /dev/cdrom /qswz 从光盘的安装包中安装DHCP rpm -ivh dhcp-4.1.1-38.P1.el6.centos.i6 ...

  7. 2019最新WEB全栈架构师第八期视频教程

    下载链接:https://www.yinxiangit.com/117.html

  8. Filter过滤器学习

    一.Filter简介 Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态 ...

  9. 行数据库VS列数据库

    一.介绍 目前大数据存储有两种方案可供选择:行存储和列存储.业界对两种存储方案有很多争持,集中焦点是:谁能够更有效地处理海量数据,且兼顾安全.可靠.完整性.从目前发展情况看,关系数据库已经不适应这种巨 ...

  10. .Net基础篇_学习笔记_第七天_计算质数(找出0-100以内说有质数)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...