'creating links that function within an iframe of a php document

I have an application form I need to work into an iframe, but I'm having a hard time with the links for it. Because the iframe was initially giving me errors, I started a work around by having a workaround.php file made that would be read as:

<!DOCTYPE html><html><?php echo file_get_contents($_REQUEST['url']); ?></html>`

Then in the iframe on my page I wrote:

<style><!--iframe.Application {
overflow: hidden;
}
--></style>
<iframe width="100%" height="800px" style="height: 100vh;" class="Application" scrolling="no" src="https://www.mywebsite/workaround.php?url=https://theotherwebsite.com"></iframe>

This worked out very well and I now had the form loading seamlessly onto my website. The next issue was that the links are not working. Any root-relative link within the iframe form was linking to "https://mywebsite.com/page2" rather than to "https://theotherwebsite.com/page2".

Now the manager of the website with the form would be able to change these relative links to absolute links, so this isn't a huge obstacle. To test if it would work, I edited the links in my browser to be an absolute to:

<a href="https://theotherwebsite.com/page2">

For this the iframe refused to connect. I'll need to continue to use workaround.php. Next I tried:

<a href="https://www.mywebsite/workaround.php?url=https://theotherwebsite.com/page2">

For a moment, I see the 2nd page load within the iframe, but then the page opens outside of the iframe in the same tab & window. Additionally, the page that loads is "https://www.mywebsite/workaround.php?url=https://theotherwebsite.com/page2" At this point, I'm unsure of what link would function and stay within the iframe. I tried to add the "_parent" target.

<a href="https://www.mywebsite/workaround.php?url=https://theotherwebsite.com/page2" target="_parent">

but this changed nothing from my previous attempt. I tried likewise with _self and _top to find no change. _blank still functioned to open the page in a second tab.

At this point I'm not familiar enough with iframes to know what else to attempt. I hope my explanation of past attempts and results is easily understood. If any of you have a suggestion of what could be a solution please let me know!

TLDR: How do I open a link within an iframe of a php document without it opening a new tab?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source