简体   繁体   中英

Post a form into an iframe on another page

I have a page from a 3rdparty I want to post to another page into an iframe so that tha layout is maintained. So i have host.com/pageA. This contains the form

host.com/pageB This contains the iframe

vendor.com/reallyComplicatedUrlthatSoundsFancyButMeansNothing

I want to post the results from pageA to pageB where the pageB contains the iframe into which the results are posted.

Target=iframe doesn't work since the iframe is on another page.

Please help

It will have to be done in combination of server and client code. Something like...

PageA.php

<form action="PageB.php" method="post">
    <input name="field1">
    <input name="field2">
    <input type="hidden" name="PageAToPageB" value="SomeString">
</form>

PageB.php

<?php 
    if ($_POST["PageAToPageB"] == "SomeString")
    {
?>
        <form id="PageAToPageBForm" target="iFrameName" method="post">
            <input name="field1" value="<?= $_POST['field1'] ?>">
            <input name="field2" value="<?= $_POST['field2'] ?>">
        </form>

        <script type="text/javascript">
        $(function(){
            $("#PageAToPageBForm").submit();
        });
        </script>
<?php
    }
?>

我认为唯一的方法是使用GET方法,例如:

<iframe src="host.com/pageB?firstparm=1&secoundparm=2..."</iframe>

You will need to "prepare" you parent page...try this way:

Your links in page A would be

<a href="pageb.htm?iframepage1.htm">Iframe page 1</a> <a href="pageb.htm?iframepage2.htm">Iframe page 2</a>

In page B

<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<script type="text/javascript">
<!--

function loadIframe(){
if (location.search.length > 0){
url = unescape(location.search.substring(1))

window.frames["myiframe"].location=url
}
}

onload=loadIframe
//-->
</script>


</HEAD>
<BODY>


<iframe name="myiframe" id="myiframe" src=""></iframe>

</BODY>
</HTML>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM