typescript - 如何在打字稿中显示留言
问题描述
我正在我的项目中实现 Paytm 网关集成并成功完成,但是当我调用 paytm api 时,api 页面显示在其他 chrome 窗口打开(弹出)上,所以当我关闭该窗口时,它没有向我显示警报或在窗口上留言,所以如何在打字稿中实现
这是我的 Ts 代码
private externalWindow = null;
this.externalWindow.addEventListener('beforeunload', function (e) {
e.preventDefault();
e.returnValue = '';
});
this.externalWindow = window.open(this.url, '', 'width=1024,height=600,left=200,top=200');
html
<Window [url]="api"></Window>
我搜索了许多资源和堆栈溢出,但对此没有任何解决方案。
任何帮助表示赞赏和愉快的编码
解决方案
您好@Developer,当您的新窗口在不同窗口上通过 API 调用打开时,无法beforeunload
在其他窗口上处理事件,因为您使用的是 2 个不同的浏览器,因此如果您将beforeunload
代码放入代码中,那么它将仅运行父 chrome 窗口,它不会在子 chrome 上工作,所以我的建议是iframe
在同一个窗口上显示并在某些条件下显示 隐藏它div
例如
<div *ngIf="showPortal">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" [src]="url | safeHtml" allowfullscreen scrolling="no"></iframe>
</div>
</div>
你必须使用safehtml
这是管道名称这是embed-responsive
embed-responsive-16by9
引导类
import { DomSanitizer } from '@angular/platform-browser';
import { Pipe } from '@angular/core';
@Pipe({name: 'safeHtml'})
export class Safe {
constructor(private sanitizer:DomSanitizer){}
transform(value: any, args?: any): any {
return this.sanitizer.bypassSecurityTrustResourceUrl(value);
// return this.sanitizer.bypassSecurityTrustStyle(style);
// return this.sanitizer.bypassSecurityTrustXxx(style); - see docs
}
}
绕过安全性并相信给定的值是一个安全的资源URL
,即一个可以用来加载可执行代码的位置,比如<script src>
,或<iframe src>
。
推荐阅读
- git - 将主分支重置为功能分支
- c# - 获取从曲线覆盖的距离?
- postgresql - JPA EclipseLink:处理默认值
- javascript - 如何将div的旋转信息获取到js中的变量中
- java - 如果使用 LinkedList add 方法修改了底层列表,是否修改了 iterator.next?
- c# - C# WebApi 授权来自依赖注入类和实体框架的访问函数
- amazon-web-services - IdentityPoolRoleAttachment 资源无法更新
- html - 移动设备上的 Zendesk 表单在打开/关闭时更改了我的网站 html 内容和 css
- apache-spark - 如何根据链式条件过滤 Spark DataFrame?
- d3.js - 使 x 轴和刻度在 d3 中消失