View Full Version : retrieving iFrame IDs

01-07-2009, 01:03 PM
Hi, I am sure this is going to be a one line fix, but I just cannot figure it out.

The plan is to have a set of pages which people (our partners) load into their own websites via an iFrame. I want to be able to find out which iFrame loaded my page so that I can use the relevant stylesheet / partner commission code for the duration of a visitors session. I do not have access to the page where the iFrame tag is placed but I can insist that they use IDs issued by ourselves.

My idea was to read out the ID from the iFrame tag that calls our pages and then go from there.

I have been trying out various options of getElementsBy, for example

but whatever I try with getElementsByxxx only seems to work if I am already in the page containing the iFrame tags. As soon as I try the same code in the child page, I just get zero response.

Does anyone have any tips for me?

Many thanks

01-12-2009, 06:31 AM
unfortunately, this may not be possible. if the main page is on their site, and they are loading pages from your site, this creates a security issue that the browser will not let happen. this is cross frame/site browsing. it will only work if they are loading pages into the iframes from their site. the content of your pages can be loaded no problem, but your pages cannot access the parent window via script nor can the parent window access the pages within the iframe .

01-12-2009, 06:43 AM
It's called the same-origin policy - client-side scripts do not have access to data beyond their own domain (subdomains are considered outside).

You can however ajax their page in through a server-side script and iframe that page. You would then have full access through the iframe.document.getElementById(id).

01-12-2009, 11:16 AM

I thought it may be something like this...

I think I will just have them add their Ids to the URL in the src, that is going to be heaps less complicated than diving into Ajax!

Many thanks for your responses.