Iframe Submission then Redirect

2019-08-15 01:30发布

How can i make an iframe keep its default submission but after redirect the user to another page. I have heard i need to do this redirection on the server side but do not know what this means.

Below is what i tried but it cancels the default iframe submission and just redirects.

function convert() {
            document.location = '/sidingsuccess';
}

with

onSubmit="convert();"

on the iframe code

3条回答
男人必须洒脱
2楼-- · 2019-08-15 02:12

On the server you can, after your submission is finished, use the header function to redirect the page to another page (say example.php) by doing:

header('Location: example.php');

is that what you're looking for?

查看更多
冷血范
3楼-- · 2019-08-15 02:16

Replace your following line:

document.location = '/sidingsuccess';

for this one:

window.top.location.href = '/sidingsuccess';

that should do it.

查看更多
Melony?
4楼-- · 2019-08-15 02:19

Submit form to hidden iframe.

iframe HTML:

<g:form controller="..." action="submit" method="POST" target="hidden-frame">
...
</g:form>

<iframe id="hidden-frame" style="display: none" onload="onSubmitCompleted"></iframe>

<script>
    function onSubmitCompleted() {
        window.top.location.href = <redirect url>
    }
</script>

Controller:

/*process submission */

render("<html><head><script>window.parent.onSubmitCompleted();</script></head><body></body></html>");
查看更多
登录 后发表回答