duannao8450 2016-07-01 12:47
浏览 300

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

I have website in PHP.And my situation is that I have checkout page that I need to click on submit button for payment process in iframe window. After complete payment process, I need to close iframe window and redirect to success page.But iframe did not close and page redirected into iframe.

Code look like this:

<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>

And below code is open in 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>

So, is there any way to close iframe window on reload page?

Many thanks in advance for recommendations.

  • 写回答

1条回答

  • dongxin9759 2016-07-01 12:54
    关注

    You can set a class for your iframe, like:

    <iframe class="myiframe"></iframe>
    

    And play with some JS, when form submited, update class="myiframe" and add 'display: none;'.

    For redirection, you can use href.location

    How to hide your iframe:

    iframeToHide = document.getElementsByClassName("myiframe");
    iframeToHide.style.display = "none";
    

    How to redirect:

    window.location = "http://www.yoururl.com";
    

    Note, this is a JS solution, with PHP I don't know if you will be able to solve this.

    Cheers!

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算