如何使用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.

doujiaoben28596
doujiaoben28596 我在我的问题中添加了完整的代码。
4 年多之前 回复
dro7152
dro7152 那是......不是......代码......这是一个随机的HTML标记。
4 年多之前 回复
dongshuo6185
dongshuo6185 信息不足。你是如何插入那个iframe的?你是什​​么意思“但iframe没有关闭,页面重定向到iframe”?向我们展示一些关于我的问题的代码。
4 年多之前 回复
drx3157
drx3157 如果您的iframe中包含php代码,则无法在iframe外部重定向。您可以尝试在新选项卡中打开重定向页面,然后关闭其他选项卡
4 年多之前 回复
duanfu1942
duanfu1942 通过关闭iframe窗口,您的意思是要从DOM中删除特定的iFrame元素?
4 年多之前 回复
duancoubeng5909
duancoubeng5909 请显示一些代码?
4 年多之前 回复

1个回答

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!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问