Forum Moderators: open

Message Too Old, No Replies

Iframe force parent load

         

Progged

4:46 pm on Mar 18, 2004 (gmt 0)

10+ Year Member



I run a phpnuke site, and in one of the modules is a simple iframe with dynamic content in the actual frame (playlist for a radio station). I don't want users to be able to access the child frame without the main page and basically I want to force the child frame to open the main page if it is access directly. I have seen examples for standard frames, but they do not work for iframes. Please be aware that I am a js novice. Does anybody have any suggestions?

Thanks,
Chan
Progged Radio

isitreal

8:02 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just stick this code in your iframe content page like this:

<html>
<head>
<title></title>
<script type="text/javascript">
if (top.location == self.location) //if page is not in its frameset
{
top.location.href = your_top_page_url;// relocate the page to the container frame, use the absolute path
// for example: top.location.href = '/folder/page1.html';
}
</script>
</head>

This works if you have a single page in the iframe, it's more complex if you have multiple ones and want the container page to reload the correct content page

Progged

8:42 pm on Mar 18, 2004 (gmt 0)

10+ Year Member



Does it have to go in the <head> section? I have a header.php that is used by several pages, and 2 of them need to be directed to different pages.

isitreal

9:30 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



No, you can put it in the body

Progged

7:00 am on Mar 19, 2004 (gmt 0)

10+ Year Member



Worked like a charm. I am in your debt!

isitreal

6:17 pm on Mar 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Glad it worked, easiest way to repay a debt like that is to answer some else's question when you know it.