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

时间:2016-07-01 12:47:15

标签: javascript php html css iframe

我有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窗口?

非常感谢您提出建议。

1 个答案:

答案 0 :(得分:0)

您可以为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我不知道你是否能够解决这个问题。

干杯!