Can't get function caller if the caller is from a function within a popup window

Discussion in 'Javascript' started by Mark, Apr 1, 2004.

  1. Mark

    Mark Guest

    The situtation is that I'm trying to ensure that certain functions are
    only called by functions that I want them to be called from. I have a
    popup window which has a function which calls a function in the opener
    window (this works fine). The only thing is when I go to get the
    caller property of the function in the opener window it is null, it
    does not return the function in the popup window that called it.

    Any ideas?
     
    Mark, Apr 1, 2004
    #1
    1. Advertising

  2. Mark wrote:
    > The situtation is that I'm trying to ensure that certain functions are
    > only called by functions that I want them to be called from. I have a
    > popup window which has a function which calls a function in the opener
    > window (this works fine). The only thing is when I go to get the
    > caller property of the function in the opener window it is null, it
    > does not return the function in the popup window that called it.


    The - caller - property was not standardised into ECMAScript so it isn't
    that widely supported. But separate browser windows are separate script
    environments and they usually care about which window various object
    belong to (functions being objects in this sense).

    Usually though, you prevent functions that should not call other
    functions form doing so by not coding the function calls into the bodies
    of those functions. You seem to have something else in mind entirely, so
    it is probably going to be necessary to answer the question: why?

    Richard.
     
    Richard Cornford, Apr 1, 2004
    #2
    1. Advertising

  3. Mark

    Mark Guest

    "Richard Cornford" <> wrote in message news:<c4hdd8$4ja$1$>...
    > Mark wrote:
    > > The situtation is that I'm trying to ensure that certain functions are
    > > only called by functions that I want them to be called from. I have a
    > > popup window which has a function which calls a function in the opener
    > > window (this works fine). The only thing is when I go to get the
    > > caller property of the function in the opener window it is null, it
    > > does not return the function in the popup window that called it.

    >
    > The - caller - property was not standardised into ECMAScript so it isn't
    > that widely supported. But separate browser windows are separate script
    > environments and they usually care about which window various object
    > belong to (functions being objects in this sense).
    >
    > Usually though, you prevent functions that should not call other
    > functions form doing so by not coding the function calls into the bodies
    > of those functions. You seem to have something else in mind entirely, so
    > it is probably going to be necessary to answer the question: why?
    >
    > Richard.


    Thanks for the reply Richard. I have since found a way to do what I
    need without using the caller property. I had the popup function parse
    its name as a string argument to the opener window function and then
    eval the string to test if the popup function existed. The last line
    of the popup function being self.close() so that the eval would fail
    when the popup was closed. I also used the onFocus event handler in
    the opener window to close the popup when it lost focus.
     
    Mark, Apr 3, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Earl Teigrob
    Replies:
    4
    Views:
    1,199
    Vidar Petursson
    Jun 5, 2004
  2. David
    Replies:
    9
    Views:
    3,796
    David
    Sep 14, 2006
  3. Jens Peter Hansen
    Replies:
    7
    Views:
    560
    Randy Webb
    Jun 19, 2004
  4. Raffi
    Replies:
    4
    Views:
    240
    Dr John Stockton
    Aug 12, 2004
  5. Thomas Mlynarczyk

    Function.caller if not called from within a function

    Thomas Mlynarczyk, Feb 26, 2005, in forum: Javascript
    Replies:
    4
    Views:
    203
    Thomas Mlynarczyk
    Feb 26, 2005
Loading...

Share This Page