[英]How to close iframe window on reload page with javascript
我有PHP网站,我的情况是我有结帐页面,我需要在iframe窗口中单击提交按钮进行付款过程。 完成付款过程后,我需要关闭iframe窗口并重定向到成功页面。但是iframe没有关闭,页面已重定向到iframe。
代码如下:
<form><input type="button" name="payfort" value="Continue" onclick="CreditPay();" id="payfort" class="payfort" /></form>
<script type="text/javascript">
function CreditPay() {
var pop = document.getElementById('popup-win');
pop.style.display = 'block';
document.getElementById('overlay').className = 'show';
document.getElementById('payfortForm').submit();
return false;
}</script>
下面的代码在iframe中打开:
<div class="popup-win" id="popup-win" style="display: none;">
<div class="popup-header">
</div>
<div class="popup-subtitle">
Transaction Value:<span class='currency-txt'>AED 17.00</span>
</div>
<iframe id="ifrmPAYFORT" name="ifrmPAYFORT" style="width: 100%; height: 450px"></iframe></div>
<div class="overlay" id="overlay"></div>
<form METHOD="post" ACTION="http://localhost/phppayfort/success.php" id="payfortForm" name="payfortForm" target="ifrmPAYFORT">
<input type="hidden" name="service_command" value="<?php echo $requestParams['service_command'] ?>">
<input type="hidden" name="language" value="<?php echo $requestParams['language'] ?>">
<input type="hidden" name="merchant_identifier" value="<?php echo $requestParams['merchant_identifier'] ?>">
<input type="hidden" name="access_code" value="<?php echo $requestParams['access_code'] ?>">
<input type="hidden" name="signature" value="<?php echo $signature ?>">
<input type="hidden" name="return_url" value="<?php echo $requestParams['return_url'] ?>">
<input type="hidden" name="merchant_reference" value="<?php echo $requestParams['merchant_reference'] ?>">
</form>
那么,有什么方法可以关闭重新加载页面上的iframe窗口吗?
在此先非常感谢您的建议。
您可以为iframe设置一个类,例如:
<iframe class="myiframe"></iframe>
并在提交表单时使用一些JS,更新class =“ myiframe”并添加'display:none;'。
对于重定向,可以使用href.location
如何隐藏您的iframe:
iframeToHide = document.getElementsByClassName("myiframe");
iframeToHide.style.display = "none";
如何重定向:
window.location = "http://www.yoururl.com";
注意,这是一个JS解决方案,使用PHP我不知道您是否能够解决这个问题。
干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.