gpt4 book ai didi

javascript - 带 Angular 动态 iframe 源

转载 作者:行者123 更新时间:2023-11-28 17:16:36 25 4
gpt4 key购买 nike

我正在尝试将支付系统与 Angular 一起使用。在支付网关 API 中,3D 安全页面以 json 形式公开为 html。我正在尝试将此 html 放入 iframe 中。主要问题是html没有显示。当我尝试在浏览器上检查元素时,iframe 中有 html 代码但未显示。其原因何在?我该如何解决这个问题?

付款.component.ts:

this.applicationService.pay(this.card).subscribe((data: any) => {
this.modalContent = data.content;
}

payment.component.html

<iframe [innerHTML]="modalContent | sanitizeHtml" frameborder="0"></iframe>

3D 安全内容示例:

<!doctype html>↵<html lang="en">↵<head>↵    <title>iyzico Mock 3D-Secure Processing Page</title>↵</head>↵<body>↵<form id="iyzico-3ds-form" action="https://sandbox-api.iyzipay.com/payment/mock/init3ds" method="post">↵    <input type="hidden" name="orderId" value="mock64-7127975743472898iyziord">↵    <input type="hidden" name="bin" value="405418">↵    <input type="hidden" name="successUrl" value="https://sandbox-api.iyzipay.com/payment/iyzipos/callback3ds/success/37">↵    <input type="hidden" name="failureUrl" value="https://sandbox-api.iyzipay.com/payment/iyzipos/callback3ds/failure/37">↵    <input type="hidden" name="confirmationUrl" value="https://sandbox-api.iyzipay.com/payment/mock/confirm3ds">↵    <input type="hidden" name="PaReq" value="66e28140-1079-4f29-81c6-0220c720620e">↵</form>↵<script type="text/javascript">↵    document.getElementById("iyzico-3ds-form").submit();↵</script>↵</body>↵</html>

最佳答案

使用以下代码片段 -

ts

@ViewChild('iframe') iframe: ElementRef;

this.applicationService.pay(this.card).subscribe((data: any) => {
this.setIframe(this.iframe);
}

private setIframe(iframe: ElementRef): void {
const win: Window = iframe.nativeElement.contentWindow;
const doc: Document = win.document;
doc.open();
doc.write(this.modalContent);
doc.close()
}

html

<iframe #iframe frameborder="1"></iframe>

工作副本在这里 - https://stackblitz.com/edit/angular-jc3qew

关于javascript - 带 Angular 动态 iframe 源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53343911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com