Click here to Skip to main content
15,885,056 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am working on a webpage which I embedded an external form page into with Iframe. I detected the external form page is configured to redirected to leave a than you message within the iframed external form page but I the functionality I need is that I want the parent or whole page to redirect to a targeted page on clicking submit of the external iframed form page.

Parent Page Contain External Iframed Page:
<div class="sign-in-box">
<div class="iframe-container" style="overflow:hidden; padding-top: 56.25%; position:relative; height: 100%">
<iframe src="http://127.0.0.1/SignIn/docs/index.php/formbuilder/frontend/viewform/?form=2" style="border: 0; height: 100%; left 0; position: absolute; top: 0; width: 100%;"></iframe>
</div>


External Iframed Page:
I am trying to put code here but not working, here is the link to the original post on stackoverflow: php - How to make Iframe From Redirect the Parent or Whole Web Page? - Stack Overflow[^]

What I have tried:

I have tried couple of solutions but not working so I guess I need to upload my code with I have attached below.

Pls I will appreciate good contributing solution.

Thank you.
Posted
Updated 3-Mar-21 21:02pm

1 solution

If you want to redirect the parent page from iFrame, use javascript:
JavaScript
top.location = '<your redirect url>';

If you want to redirect from parent to iFrame, use JavaScript:
JavaScript
document.getElementById("iframeId").src = '<your redirect url>';

If you are looking for something else, please help me understand your question.

you can add iframeId like:
JavaScript
<iframe id="iframeId" src="http://127.0.0.1/SignIn/docs/index.php/formbuilder/frontend/viewform/?form=2" style="border: 0; height: 100%; left 0; position: absolute; top: 0; width: 100%;">
                    </iframe>
 
Share this answer
 
v2
Comments
cHl Security 14-Jul-19 19:15pm    
Please sir, below is my Iframe code: I can't find an Iframe ID for it. Can you give me proper code to make this function work with my code? Thanks.






cHl Security 14-Jul-19 19:20pm    
Please sir, I have tried your code, I tested the script on both iframe and parent page but it keeps redirecting automatically instead of redirecting only when the iframe formsubmit button is clicked. Below is my Iframe code: I can't find an Iframe ID for it. Can you give me proper code to make this function work with my code? Thanks.

<div class="sign-in-box">
                <div class="iframe-container" style="overflow:hidden; padding-top: 56.25%; position:relative; height: 100%">
                <iframe src="http://127.0.0.1/SignIn/docs/index.php/formbuilder/frontend/viewform/?form=2" style="border: 0; height: 100%; left 0; position: absolute; top: 0; width: 100%;">
                    </iframe>
                </div>
          </div>
cHl Security 14-Jul-19 19:21pm    
Please I need solution on where and how to properly apply the code.
cHl Security 14-Jul-19 19:23pm    
The main function I need is that I want the parent page to redirect to a target page when submit button is being clicked on the iframe form page.
Anurag Gandhi 24-Jul-19 13:37pm    
I updated the solution. Please have a look.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900