Valhalla Legends Archive

Programming => Web Development => Topic started by: KrAzY_NuK on October 22, 2004, 03:33 PM

Title: Client-Side variables and such
Post by: KrAzY_NuK on October 22, 2004, 03:33 PM
I'm developing a small web-app at work, and I haven't really done a lot of web development.

Suppose you had this scenerio:
Main window (a) opens a new window (b) via "window.open()"
In window (b) i have a form that i want filled out, and i want the information returned to window (a)

is this at all possible?
i imagine i can refresh window (a) after window (b) has hit submit and get the data from the server.  I was just hoping there was a way that I wouldn't have to go back to the server for it.

Thanks!
Title: Re: Client-Side variables and such
Post by: j0k3r on October 22, 2004, 03:42 PM
This probably can (and should) be done another way, why do you need to open a new window and send information back to the old one?
Title: Re: Client-Side variables and such
Post by: KrAzY_NuK on October 22, 2004, 04:04 PM
That's what seemed like the easiest thing to do at the time.  The web-app is going to be used to recycle services on servers, or actual servers themselves.  It will also allow a user to setup a schedule, or run the chosen operation at that moment.

I figured that logically seperating everything would make sense, and i wanted to keep all of the information available on that one page without cycling through a bunch of pages

The code can be found at:
http://home.cc.umanitoba.ca/~umbewcyk/webapp.zip
Title: Re: Client-Side variables and such
Post by: Grok on October 24, 2004, 12:40 PM
Sure it's possible.  Window B is a child window of Window A.  In Javascript, use the .parent property to reference the (A) window.  Create a javascript function in Window A's code that accepts values from the caller.  In your (B) code, call Me.parent.YOURFUNCTION(parameters) to pass back what (A) needs to know.
Title: Re: Client-Side variables and such
Post by: MyndFyre on October 24, 2004, 06:38 PM
Quote from: Grok on October 24, 2004, 12:40 PM
Sure it's possible.  Window B is a child window of Window A.  In Javascript, use the .parent property to reference the (A) window.  Create a javascript function in Window A's code that accepts values from the caller.  In your (B) code, call Me.parent.YOURFUNCTION(parameters) to pass back what (A) needs to know.

I don't believe that would work, at least cross-browser.  The window.parent property is supposed to refer to the window containing a frameset, if one exists.

However, I recently set up something similar using Flash in the second window.  Basically, I set a function in the second window:

Second window Script:

var __parentFunc;
function doSetParentFunctionCall(ParentFunc) {
  __parentFunc = ParentFunc;
}


First page:

var childWindow;
function __onLoadHandler() {
  childWindow = window.open([i]parameters[/i]);
  childWindow.doSetParentFunctionCall(doProcessData);
}

function doProcessData(x, y)
{
  // ,,,
}


The flash movie then called:


javascript:__parentFunc(x, y);


to call the parent function.
Title: Re: Client-Side variables and such
Post by: KrAzY_NuK on October 25, 2004, 09:02 AM
cool cool!
I'll try those out and see what goes from there.

I don't think I need to worry about cross browser.  Everybody here should be using IE because they like to keep things *standard*.

*Edit:  I've tried both methods at *still* can't seem to get anything to work   :(
Title: Re: Client-Side variables and such
Post by: Grok on October 25, 2004, 02:24 PM
Quote from: KrAzY_NuK on October 25, 2004, 09:02 AMI don't think I need to worry about cross browser.  Everybody here should be using IE because they like to keep things *standard*.

Good one!  Haha.  I get it!
Title: Re: Client-Side variables and such
Post by: KrAzY_NuK on October 25, 2004, 03:55 PM
i figured it out!

window (A) has the following:

      function show( newVal )
      {
        alert( newVal )
      }
      function add()
      {
        var win = window.open( "add.asp" );       
        return;
      }


and window (B):

      function add()
      {
        opener.show(document.getElementById("add").value);
        window.close();
      }


so when i click the "ADD" button in window (B) it calls the function add() which runs the function show() from the calling page.

This is great!   Thanks so much guys!