如何用javascript关闭重新加载页面的iframe窗口


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&nbsp; 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我不知道你是否能解决这个问题。

干杯!