May 29, 2020
한 컴포넌트 안에서 mobiliance 결제 iframe을 랜더해야하는 상황이다.
#1
#2
message
이벤트를 발생시켜 iframe을 제거한다.<iframe [class.show]="isProcessing && (payInfo.pg == 'mob' || payInfo.pg == 'kakaopay' || payInfo.pg == 'toss')"
name="phoneIframe" id="phoneIframe" width="100%"></iframe>
iframe[name=phoneIframe] {
display: none;
border: none;
height: calc(100vh - #{$header-height + $my-cash-height + $tab-height + 5px});
&.show {
display: block;
}
}
<div class="iframe-container"
[class.show]="isProcessing && (payInfo.pg == 'mob' || payInfo.pg == 'kakaopay' || payInfo.pg == 'toss')"></div>
.iframe-container {
display: none;
::ng-deep iframe[name=phoneIframe] {
border: none;
height: calc(100vh - #{$header-height + $my-cash-height + $tab-height + 5px});
}
&.show {
display: block;
}
}
export class MobileCashComponent {
@HostListener('window:popstate')
@HostListener('window:message')
closePayment() {
if (this.isProcessing) {
this.closeMCASHPaymentResult();
}
}
execute() {
this.createIframe();
super.execute();
history.pushState(null, null, location.href);
}
createIframe() {
const iframeContainer = document.querySelector('.iframe-container');
let iframe = iframeContainer.querySelector('#phoneIframe');
if (iframe) iframe.remove(); // 기존 태그 제거해버리기
iframe = document.createElement('iframe');
iframe.name = 'phoneIframe';
iframe.id = 'phoneIframe';
iframe.style.width = '100%';
iframeContainer.appendChild(iframe);
if (this.payInfo.pg === 'toss' || this.payInfo.pg === 'kakaopay') {
document.getElementById('phoneIframe').src = `${this.apiClient.base_api_url}/payment/mobilians/close`;
}
}
}
참고 :