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!

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况