Reputation: 31
On our website we have a page that pulls content from another location in to an iFrame. I would like to know how I can create a link to the parent page and have a specific page load in the iFrame.
So, I'd like to create a link to http://xxx.xxx.com/page and have the iFrame on that page load http://yyy.xxx.com/anotherpage
Upvotes: 3
Views: 13829
Reputation: 131
I was thinking:
Forms like https://www.w3schools.com/tags/att_form_method.asp this should give something like "index.php?getresult=someinput" right?
so if you link to your page like:
xxx.xxx.com/index.php?showpage=myrequestedpage
and
xxx.xxx.com/index.php
index.php contains
<?php
//pseudo-code to:
//function getiframe(){
//$showpage = $_GET (this should get "myrequestedpage") .".php";
//if no ?showpage available then $showpage = "defaultpage.php"
//}
// return $showpage;
?>
<iframe src="http://xxx.yyy.com/<?php getiframe(); ?>"></iframe>
I was having this in mind while I started searching for easyer/better solutions to the question Original Poster had, but I think this ... should ... work right?
ps. sorry for gravedigging(just noticed after writing the pseudocode), but i have the same question and thisone popped up on top in google, so hoping this would bring my thoughtprocess to a finished product as well and maybe someone has better idea's years later.
edit: tested this to be working indeed. xxx.xxx.com/index.php?pagina=specificpage
<?php
if (empty($_GET['pagina'])) {
$pagina = "home.php";
}else{
$pagina = $_GET['pagina'].".php";
}
?>
<iframe src="<?php echo $pagina; ?>" style="border:none;" title="websites" height="100%" width="100%" name="target_frame"></iframe>
Upvotes: 0
Reputation: 51
You should give your iframe element a name attribute and then target that name in your anchor tag.
Like so:
<iframe src="iframe.htm" name="iframe_a"></iframe>
<a href="http://www.urltowebsite.com" target="iframe_a">My link</a>
See the MDN documentation for more info.
Hope it helps!
Upvotes: 5
Reputation: 1401
you'd have to add an iframe to http://xxx.xxx.com/page like this:
<iframe src="http://xxx.yyy.com/anotherpage"></iframe>
Upvotes: 1