我正在我的项目中实现Paytm网关集成并成功完成,但是当我调用paytm api时,该api页面显示在其他chrome窗口中打开(弹出),因此当我关闭该窗口时,它不会在窗口中显示提醒或提示消息,因此如何在打字稿中实现
这是我的电话代码
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>
并且我搜索许多资源和堆栈溢出,但对此没有任何解决方案。
感谢您的帮助,并祝您编程愉快
Hello @ Developer,当您使用不同窗口的API调用打开新窗口时,无法处理其他窗口上的beforeunload
事件,因为您使用的是2种不同的浏览器,因此,如果将beforeunload
代码放入您的代码,它将仅在父chrome窗口上运行,而在子chrome上不起作用,因此我的建议是在同一窗口上显示iframe
,在show hide中显示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>
。