SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Los Angeles, CA
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Data across iframe and its parent

    Ok, I need to execute some code after the page loads. So I'm having the code execute in an iframe. Now, the iframe contains JS vars and/or page elements that I need to use in the parent frame. How can I gain access to either of these in the parent?

    I've tried all sorts of combos of frames[0].document.getElementById('name').innerHTML and so forth and I just can't seem to gain access to the document in the iframe from the parent.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I need to execute some code after the page loads.
    You can do that without an iframe:
    Code:
    window.onload=function()
    {
    	alert("hello");
    
    	//do other stuff
    }
    Now, the iframe contains JS vars and/or page elements that I need to use in the parent frame. How can I gain access to either of these in the parent?
    window.frames["frameName"].thevar

    and

    window.frames["frameName"].document.getElementById("elementID")

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Los Angeles, CA
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need the code to execute after user-initiation. Also, the code is itself JS code that includes an external JS file. it's an ad tag, basically. I need to load the page, but then prompt execution of the ad tag only when the user initiates it. iframe works fine for this, but then I just cannot get the data from the iframe back into the parent, no matter what different ways I try. I've tried just getting the vars themselves, as you suggest; i've also tried printing vars into an element and getting the innerHTML of the element.


    window.frames["frameName"].thevar doesn't work. In IE, it will work when the whole page first loads, but after I refresh the iframe, it won't work again. In Firefox it doesn't work at all.

    window.frames["frameName"].document.getElementById("elementID") doesn't work either, in either browser, at any point.

    :-(


Bookmarks

Posting Permissions

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