www.webdeveloper.com
Results 1 to 6 of 6

Thread: Passing properties from parent window to child

  1. #1
    Join Date
    May 2010
    Posts
    5

    Passing properties from parent window to child

    Hey,

    In javascript I need to pass a variable or function or something from the parent window to the child window. There will be a URL in the parent that needs to be passed into the child so when you click on the link in the child window it pulls in the link from the parent's js. Like this (ignore my rubbish javascript as I'm just writing it to explain my point!)...

    Parent window
    var variableName="http://www.google.com"
    (send variable to child window)

    Child window
    (pick up variable from parent window and drop it into the link's URL)
    <a href="(variableName);">google</a>


    This might seem like a crazy way of doing things but it's totally neccasery in the project I'm working on for various reasons.

    Not sure if its a variable it needs but either way it needs to be in the js somewhere in the parent and the child needs to read it within the link. Everywhere I've looked on the internet shows how to do this with forms etc but I can't make it work for a URL.

    Thanks (:

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    javaScript can not establish a relationship between pages who belongs to different domains.

  3. #3
    Join Date
    May 2010
    Posts
    5
    Both pages are on the same domain, same directory in fact.

    I see where the confusion is as I've just used google as an example of the link. Let me be more specific...

    Parent page - index1.html
    Parent page produces popup as child - index2.html
    There needs to be 'index3.html' written as some type of variable in the parent page's javascript

    Child page - index2.html
    Child (index2.html) picks up the variable from parent (index1.html) and displays it in a link <a href="(variable_name_from_index1.html)">click</a>

    Is that a bit clearer?

    Thanks.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    The JavaScript build in reference of the parent from a popup, opened with window.open() method, is opener.

    Thus, the URL of the parent, seeing from the popup, should be:
    Code:
    var parentURL = opener.location.href

  5. #5
    Join Date
    May 2010
    Posts
    5
    Thanks for this.

    Problem isn't producing the popup as a child as I've done that and I'm using window.opener to talk to the parent from the child, etc. What it is: I can't work out how to get a variable from the parent page into a link in the child page.

    If parent page has:

    var variable_name="index3.html"

    How do I get this into the link into the child page so it would read:

    <a href="variable_name">click</a> - this link would go to index3.html as that is what is specified in the variable name in the parent page.

    Thanks.

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Code:
    var thatVariable=opener['variable_name']
    if that variable is a global one.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles