Forum Moderators: open
Say you call main.php from index.php with links like
<a href="main.php?page=subpage.html&target=anytarget">link</a>
In main.php write the iframe like this:
<?php
echo '<iframe src="' . $_GET['page'] . '#' . $_GET['target'] . '"></src>';
?>
(works in IE, not sure about other browsers)
It may be useful to do some validation on the query parameters. Otherwise you may find yourself lo-tec hacked with links like
yoursite.tld/main.php?page=http://www.example.com
This goes in the head section on the page with the iframe:
<script type="text/javascript">
function loadIframe(){
if (location.search.length > 0){
url = unescape(location.search.substring(1))
window.frames["iframename"].location=url
}
}
onload=loadIframe
</script>
This is for the links:
<a href="pagewithiframe.php?pagetoshowinframe.php">link example</a>