Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    retrieving iFrame IDs

    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
    parent.document.getElementsByTagName("iframe")[0].id

    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

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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 .
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • Users who have thanked brandonH for this post:

    DebbieM (01-12-2009)

  • #3
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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).
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • Users who have thanked itsallkizza for this post:

    DebbieM (01-12-2009)

  • #4
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi

    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •