• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

iFrames - accessing elements

 
Ranch Hand
Posts: 3851
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It's related to iFrames.

Say I have two iFrames in a page which renders (embeds) two other pages. Now,

I can access element of an iFrame in parent page like this:

document.aFrame.document.getElementById("anId").value

where aFrame is name of one of the frames.

I can access element of an iFrame in another iFrame like this:

parent.document.aFrame.document.getElementById("anId").value

So far it's working in all the major browsers (IE, FireFox & Chrome).

Now what if I include pages of two different domain e.g.

Instead of this:

<iframe src="f1.html" name="aFrame" />
<iframe src="f2.html" name="bFrame" />

I'll have:

<iframe src="http://www.a.com/index.html"; name="aFrame" />
<iframe src="http://www.b.com/index.html"; name="bFrame" />

Will I be able to access elements of an iFrame in parent page or in other iFrame?

I heard that browsers prevent this due to some security reasons. I also don't get alert(document.aFrame.document) when aFrame iFrame contains say google.com or javaranch.com but I get an [object] in alert when aFrame contains f2.html (a page in same domain).

What if I include a sub domain page in an iFrame which is in a page of parent domain e.g. myDomain.com has a page contains iFrame and this iFrame refers a page of something.myDomain.com (sub domain of myDomain.com)? Will I be able to access each others elements?

My main problem is I don't know how do i simulate this sub domain situation. I don't own any domain. Is it possible to do it locally?

Thanks.

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to simulate a sub domain?

DO you have firebug? Use the console or the address bar to inject an iframe into the page with createElement and appendChild. This way you can add an iframe into the page with a site that has subdomains.

Eric
 
It was the best of times. It was the worst of times. It was a tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic