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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trigger event in popup from main page

    First, I will state that I am totally inexperienced in JavaScript.

    I have a web site application written in VB.net and asp. The main page uses JavaScript to load a popup page that performs multiple tasks. The main page accepts a variety of incoming messages, only SOME of which need to be passed to this popup page for processing. I found an ugly way to pass the message to the popup by placing it in a Session variable. Now I need to cause it to be handled. I see two possibilities, and I do not have a clue how to implement either. Either one would be great:

    1. In the main page, trigger a subroutine in the popup, using JavaScript.
    OR
    2. In the popup, establish a trigger any time that Session variable changes.

    Thanks in advance for any help on this.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,643 Times in 4,605 Posts
    Even if you used (2), how would you know *when* the session variable was changed?

    Maybe it really is time to learn a tiny bit of JavaScript coding?

    (1) is certainly a possibility. For it to work, you have to *HAVE* a reference to the popped up page. Which is easy to get when you open the popup:
    Code:
    var popup = window.open("...the url...", "_blank", "...settings..." );
    ...
    popup.someFunction("this is the message"); // call someFunction in the popup window
    Problem with that: Such a reference won't survive a reload of the main page. JavaScript variables are not retained from one page load to the next.

    Now, there *ARE* ways of getting a reference to an existing popup from a new page, but they are typically a pain in the patootie to get working cross browser.

    An easier way is to instead have the popup call back to the opener window. And you could easily have it do so every, say, 100 milliseconds. Have the main window simply remember if its callback function has already been called, or not, and have it only return a meaningful value when it hasn't.

    EXAMPLE:

    On the main page:
    Code:
    <script type="text/javascript">
    var alreadyCalledForMessage = false;
    function getMessage( )
    {
        if ( alreadyCalledForMessage ) return null;
        alreadyCalledForMessage = true; 
        return "<%=messageFromTheAspNetCodePerhaps%>";
    }
    </script>
    And then, in the popup:
    Code:
    <script type="text/javascript">
    function checkForMessage( )
    {
         if ( window.opener != null && window.opener.getMessage != null )
         {
             var msg = window.opener.getMessage();
             if ( msg != null )
             {
                 ... do something with the msg ...
             }
        }
    }
    window.onload = setInterval( checkForMessage, 100 ); // check every 100 milliseconds
    </script>
    Fortunately, window.opener will remain correct even if the original code in that main window has long since been replace by a new page. And so if there is a JS function by the right name in that main window, it will get called.

    *********

    Will that do the job?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Maybe it really is time to learn a tiny bit of JavaScript coding?
    Thanks VERY much. I believe that the reference solution may work for me. I will have to play with it.

    The popup is called from my master page, and that is where all input messages are collected and sent on to appropriate routines for processing. If the client exits the master page, the popup will no longer function anyway, because our server will drop communications with them. This application is for a fantasy sports service, and the popup is to allow a client to do 1-to-1 messaging with multiple other clients. I have run the fantasy service for 22 years, and over that time have personally written over 200K lines of code. A good portion of that is for a distributed Windows software package. But I have web site support for MAC users, and am FINALLY getting around to adding the messaging function to it that it desperately needs.

    As for learning the language, I know you are right. But at 70 years old, after 22 years of retirement from IBM doing mainframe programming, I tend to reject new languages and learning projects. LOL LOL

    Thanks again for the help and good advice.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,643 Times in 4,605 Posts
    The reason I think you need the solution I proposed: With ASP.NET, all too often you end up doing a page refresh/reload without even really being aware you did so. ASP.NET *loves* to "postbacks" to the server for the silliest reasons. They can be avoided, most of the time, but all too often you aren't even aware they are done. And, yes, such a postback does destroy the reference to the popup that was held by the version of the page that opened the popup.

    Retired for 22 years at age 70. Wow. Wish I could say that. I'm age 68 (soon) and still putting in 45 to 50 hour weeks with no end in site. And have learned a new language in the past few months (C#--with all the .NET libraries that implies) and am about to learn jQuery, which (although it is based on JavaScript) might as well be a new language. Including assembly languages, I think this makes it 30 computer languages (not including variants) I have learned in my career.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks again for sharing your insight into this situation.

    30 languages is impressive. I have no idea how many languages I learned during my career with IBM, but it was not 30. The last few years of my career, I was working on the software for our submarines, and strangely enough, we had the contract to write all of the software for the Univac CPU's they contracted for, so we were using CMS-2 assembler and compiler.

    I really should not have gotten so lazy as to "settle" into my comfort zone, but that is what I have done. I stay very busy, but the great majority of my efforts are geared more to the business itself than into the software. The past 12-15 years, I try to find bits of time to squeeze in software work, and do it "quick and dirty".

    As far as any envy you may feel, there are definitely pros and cons. I love working at home, but there is a huge void in the daily interactions. And I also feel the loss of satisfaction in knowing I am not even close to being up-to-date with the state of the art, after being at on top of it for a good period of time.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,643 Times in 4,605 Posts
    Some of those languages I didn't learn too well. (Only used COBOL for maybe 3 or 4 months, for example.) But some of them I even wrote tutorials for (Prolog and Pascal, for example), so I had to know them reasonably well. And some I wrote compilers or interpreters for (C and five different flavors of BASIC and wrote libraries for Pascal and Java and C++), so those I had to know really well. To be fair, I learned assembly language for...umm...7 or 8 different microprocessors, back when they were creating new microprocessors at the rate of one a month (or so it seemed). And let's face it, there are only so many ways to create a microprocessor that has a handful of registers (well, the Z-80 had 16, depending on how you counted them, but...). And C# and Java and C++ are all close enough that the real problem is forgetting which one you are currently working in (though the libraries for each are completely different, and that's what takes the time to learn).

    I do work from home now (health issues), doing full time (and then some) contract work. But that's only been for last year.

    I do miss the halcyon days of the microprocessor. It was fun trying to cram (for example) a full language compiler into 16KB (or a BASIC interpreter into 8KB or a C compiler into 48KB).
    Last edited by Old Pedant; 02-21-2012 at 11:25 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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