Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Location
    NJ - #29 if you must know
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copying Javascript routines from one window to another

    ok. Here's what I want to do....

    I don't want to use a common .js file, although
    that may be the easiest way out.

    I'm designing a front-end page that will
    enter a month and year, then it will open
    a new window, produce a table by writing
    HTML line by line for each day of the month.

    No problem.

    Now I also want to imbed some javascript
    routines into that window. Aside from storing
    the routines in an array in the front end page
    and writing the array line by line, is there anyway
    to "read" the javascript from the front end and
    write them to the new window?

    The front end doesn't use most of these routines, it's just
    being a carrier to put them in the new window.
    however, there are going to be some routines that
    will be used in both.

    I don't want the new window to reference the
    routines from the front end window, because once
    the new window is created, it's meant to be saved
    to the hard drive, then clicked on locally and updated
    then saved again.

    The front end is only to produce the appropriate
    table cells for this window.

    I'd also like the window to have the ability to create
    a new window based on the next month, and carry
    over the data to start off the new window.

    Does this make any sense?

    Basically, I'm making one static HTML page, which will
    dynamically create a new HTML page which can be saved
    and later manipulated without losing entered data.

    and later that dynamically created page, once it's month's
    worth of data has been entered, will have the ability to
    spawn off a new dynamically created page, carrying over
    ending totals from the previous as a starting total in the new.

    George

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    There's ways. It's far easier if you either export them to the other window from the document they are in, but you can do it the other way as well. You can also execute them in the first window from the other, if you wish. The procedure to move them would be something like this:
    Code:
    // In the first window, copy to the other
    [object OtherWindow].window[[string FunctionName]] = [function FunctionName];
    
    // In the other window, copy from the first window
    var fnFunctionName = [object FirstWindow].window[[string FunctionName]];
    
    // In the other window, execute in the first window
    [object FirstWindow].window[[string FunctionName]]( arguments )
    How you access the first window from the second depends on how they are related. A popup would use window.opener, while a frame would use window.parent, or window.top. Windows that are not related can be made related by using the window.open function with their window name as one of the arguments, to create a popup relation. Note that this does not reliably work for frames.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Location
    NJ - #29 if you must know
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't execute them from the other window. Once the
    new window is created and saved to the hard drive.

    The next day/week, etc, only the new window will be
    available (locally), not off the web.

    So any/all javascript routines MUST be transferred over
    to the new window, so they can be saved with it.

    Almost like I need to have the routines stored as text
    in an array for transferring.

    Is there a way to "read" the javascript using javascript.
    That is, be able to read all javascript functions on a page
    and write them to another window

    Like you can read the HTML of a page using elements[],
    but can you read javascript of a page?

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Have you tried to alert a function - without the parentheses - some time? That's your way to read the function as text.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Regular Coder
    Join Date
    Jul 2003
    Location
    NJ - #29 if you must know
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't get it...explain..

    Thanks
    George

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Try it:
    Code:
    alert([function YourFunction]);
    See that the function is written out when it gets converted to a string? You can do the same conversion using
    Code:
    var sYourFunctionSource = [function YourFunction].toString();
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    Regular Coder
    Join Date
    Jul 2003
    Location
    NJ - #29 if you must know
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    is the function still usabe? or just displayable? when it's
    referenced that way.

    That looks like it could get real ugly, if it were say a 50 line
    function for instance.

    I'll have to toy with that to see what it does, right now, I
    can't picture it in my mind yet.

    George

  • #8
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    It's still usable (actually that is the form the function is represented as internally) but you have to be wary when it comes to scopes and variables. Also note that this does not work for closures, only for source functions. A closure must be reinstanciated from the original function.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

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