Forum Moderators: open

Message Too Old, No Replies

Links to specific page in iframe

         

th1chsn

1:55 pm on Sep 7, 2007 (gmt 0)

10+ Year Member



I have two pages named index.php and main.php. main.php has an iframe and all the links target the iframe.

But index.php page serves as an entrance page that links to main.php.

I want to open main.php from index.php with a specific page in the iframe for each link.

How can I do that?

RonPK

12:37 pm on Sep 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Should be easy as you're using PHP.

Say you call main.php from index.php with links like

<a href="main.php?page=subpage.html&amp;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

th1chsn

6:19 pm on Sep 8, 2007 (gmt 0)

10+ Year Member



I found this code and it works. Do you know if there is a security risk with it?

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>