SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2002
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Call a function in another window

    Hi!
    Is it possible to call a window's function from another window? E.g. refresh ...or any other Javascript function?

    thx in advance
    Chrisi

  2. #2
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As long as you have a handle to the window then it's no probs (frames within the same window may be accessed via the DOM)!
    Code:
    windowhandle.document.location.refresh();
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  3. #3
    SitePoint Member
    Join Date
    May 2002
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thx
    and how can I call the parent window from inside the popup's code? i'm asking because window.open is the only way I know to get a windowhandle.

    chrisi

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The syntax for addressing the popup's opener is:
    window.opener
    -OR-
    self.opener
    -OR-
    top.opener
    -OR-
    parent.opener

    Depending on how you need to reference it. All are valid if frames are not present in the popup. 'parent' will work if there is only 1 framset, otherwise 'top' will be needed.

    So, if you wanted to refresh the opening document:
    window.opener.location.refresh();
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm currently working on a project that requires:
    window.parent.parent.parent.parent.function();



    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  6. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    top.function() should be able to replace that, shouldn't it?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  7. #7
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Originally posted by Flawless_koder
    I'm currently working on a project that requires:
    window.parent.parent.parent.parent.function();



    Flawless
    lol that the chat script,

    i do like these ones tho

    this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML

    lol

  8. #8
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe I'm missing something, but wouldn't it be simpler to use...
    Code:
    window.name="parentWindowName"
    ...in the parent window itself and then simply refer to that window by using whatever name you gave it?

    Surely this would be better than a string of parent.parent.parent... or opener references and easier to keep track of too.

    Just a thought
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  9. #9
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with you Bill 100%

    If you reference the window more than once, or there are multiple windows you need to name them
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  10. #10
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope - it's not the chat script.

    It's in a system where there's about six or seven
    frames and iframes within each other.

    You obviously couldn't use top.funciotn - coz it's not
    the top window.
    You can't call it by windowname - coz i want to be able
    to know how many levels up it is ( and show that in the code for other people ).

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


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
  •