SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question returning javascript values from pop-up windows...

    Hi!

    I have a very specific question.

    I'm writing some code that makes use of Microsoft's IE 5.5+ proprietary functions. Specifically, the showModalDialog() function. This handy little function has a return value which can be set with javascript - and then accessed by its opener page.

    Problem is, there are certain restrictions with the showModalDialog function (specifically the fact that it wasn't designed to be refreshed) that render it unusable in my case. (The content of the page will be dynamic).

    So, instead, I have to come up with another solution.

    What I want is as described above: a page which opens a pop-up window. Inside this popup window, a javascript variable will store a value chosen by the user. Then, I want this variable to be accessed by the opener window. All of this done with javascript.

    Any idea?

  2. #2
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A window is opened with a pointer to the windows that opened it (called 'opener'), so therefore you could store the variable directly in the opener if that is any good.

    If thats no good you could always call back to the opener and store a pointer to the new window so that the opener can access it.

    There may be a simpler way, the DOM may specify that a window has a pointer to its children as well?
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  3. #3
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey! Thanks for your response.

    Would you mind expanding a little on the actual code. Say in the parent window I have:

    var myPopup = window.open(... blah blah ...);

    How do I get a variable value back from the child window 'myPopup'? What's the line of code in the child window that sets the 'opener' variable (which right now doesn't exist) to something. And then how do I access it in the parent window?

    Confusing stuff...!

  4. #4
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One other thing: the opener window is a .js file.

  5. #5
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Originally posted by AtomicPenguin
    Hey! Thanks for your response.

    Would you mind expanding a little on the actual code. Say in the parent window I have:

    var myPopup = window.open(... blah blah ...);

    How do I get a variable value back from the child window 'myPopup'? What's the line of code in the child window that sets the 'opener' variable (which right now doesn't exist) to something. And then how do I access it in the parent window?

    Confusing stuff...!
    The first browser window (the one that opens the page) is referred to as "opener" to the popup window. For example, if you wanted to change the page displayed in the first window from the popup, you can use this code:
    Code:
    opener.location.href = 'mypage.html';
    Likewise, if you want to change the location of the child window from the parent, you can use this code (assume the popup is named 'myPopup'):
    Code:
    myPopup.location.href = 'myPopupPage.html';
    Hope this clears some things up.

    --Vinnie


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
  •