Passing a value from an iframe to parent

Joined: 11/28/2008
User offline. Last seen 2 years 12 weeks ago.

Hi folks

I have a parent page containing an iframe. The parent page has a menu in it. I want to highlight different bits of the menu according to which page has loaded in the iframe.

So I would like to do something like this:

1. Use PHP to extract the file name (minus 'php' at the end, for the page within the iframe.
2. Use javascript onload so that the iframe sends this value (say 'pagename') to the parent page when it loads
3. The parent page, having received that variable into its header, will adjust a line of css thus:
.pagename {background-color:red;}
4. And so the menu link for pagename.php will be colored red
5. When pagename1.php is loaded into the iframe, that will send 'pagename1' to the parent page, change the CSS in the head, and therefore change the highlighted menu item from pagename to pagename1

Is this possible? There seems to be a lot of stuff online about moving variables from iframes, but mainly in the context of form entries.

http://www.highdots.com/forums/javascript-discussi...

http://www.webdeveloper.com/forum/showthread.php?t...

parent.function_name(); seems to be needed along the way

seems to be more what I need!

Blessings and thanks

Tony

Online outreach:
Internet Evangelism Day
Helping church websites:
Church Websites

Joined: 10/18/2008
User offline. Last seen 1 year 27 weeks ago.
jQuery: it can do just about

jQuery: it can do just about anything.

All you need is a simple script inside your iframe page, maybe something like:

$(document).ready(function() {
  parent.top.$(div#menuID).css('background-color', 'red');
});

I have tested this, but it might point you in the right direction.

/ * Begin Signature */
It's a strange thing about determined seekers-after-wisdom that, no matter where they happen to be, they'll always seek that wisdom which is a long way off. Wisdom is one of the few things that looks bigger the further away it is.

Joined: 06/06/2009
User offline. Last seen 1 year 42 weeks ago.
It is also worth noting you

It is also worth noting you can control the contents of the iFrame from JavaScript. So that might work for you!?

Joined: 11/28/2008
User offline. Last seen 2 years 12 weeks ago.
thanks guys bless you Tony

thanks guys

bless you

Tony

Online outreach:
Internet Evangelism Day
Helping church websites:
Church Websites