how can i close a pop up from the parent onload

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JSjones

    how can i close a pop up from the parent onload

    when a form is submitted from the main window i want a pop up window
    to open from the onclick event. i have that working, now how can i
    close the pop up window from the main window after the main window
    finishes loading? i've been racking my brain on this for the last two
    days. here is the code for the parent window that i have been testing
    with.

    testfoo.htm is just a blank html page used for testing.

    <head>
    <title>Personne l Information</title>
    <script language="javas cript" type="text/javascript">
    var newWindow;
    //alert(newWindow + " page load");

    function openDialogWin() {
    var height = "300";
    var width = "500";
    var x = (screen.width - width) / 2;
    var y = (screen.height - height) / 2;
    var Name = window.name;
    //alert(height + ", " + width);

    features = "height=" + height + ",width=" + width + ",left="
    + x + ",top=" + y;
    features += ",menubar=no,re sizable=no,titl ebar=no,scrollb ars=no,status=n o,toolbar=no,me nubar=no,locati on=no";
    var newWindow = window.open(une scape("/testfoo.htm"),
    "newWindow" , features);
    //alert(newWindow .name + " in openDialogWin") ;
    return newWindow;
    }

    function closeDialogWin( ) {
    if (newWindow && !newWindow.clos ed)
    newWindow.close ();
    }
    </script>

    </head>
    <body onLoad="closeDi alogWin();">
    <form method="post">
    <input type="submit" name="foo" value="Submit"
    onclick="openDi alogWin();">
    </form>
    </body>
    </html>

    sorry about the formatting... it looks ok in the editing window. if
    anyone can clue me in on how to format the code for the boards, i'll
    do my best to comply.

    thanks in advance

    jones
  • kaeli

    #2
    Re: how can i close a pop up from the parent onload

    In article <94aca08d.04011 40804.4689cf3b@ posting.google. com>,
    javajonesk@hotm ail.com enlightened us with...[color=blue]
    > when a form is submitted from the main window i want a pop up window
    > to open from the onclick event. i have that working, now how can i
    > close the pop up window from the main window after the main window
    > finishes loading? i've been racking my brain on this for the last two
    > days. here is the code for the parent window that i have been testing
    > with.
    >[/color]

    You redeclared newWindow, so what you did was create a local var and the
    global is unchanged.
    [color=blue]
    > features += ",menubar=no,re sizable=no,titl ebar=no,scrollb ars=no,status=n o,toolbar=no,me nubar=no,locati on=no";
    > var newWindow = window.open(une scape("/testfoo.htm"),
    > "newWindow" , features);[/color]

    Take away that "var".
    newWindow = ...

    You don't need to return newWindow from that function either, since
    nothing caught it anyway.

    --
    --
    ~kaeli~
    Not one shred of evidence supports the notion that life is
    serious.



    Comment

    • Kevin Jones

      #3
      Re: how can i close a pop up from the parent onload

      i removed the "var", but now i am getting an "Error: 'newWindow' is
      undefined". also, i am passing 'newWindow' back and forth between the
      parent and child windows.

      jones

      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Kevin Jones

        #4
        Re: how can i close a pop up from the parent onload

        i removed the "var", but i'm still running into the same problem -
        newWindow is undefined and is not being close by the closeDialogWin
        function.

        jones

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • kaeli

          #5
          Re: how can i close a pop up from the parent onload

          In article <40057ece$0$703 07$75868355@new s.frii.net>,
          javajonesk@hotm ail.com enlightened us with...[color=blue]
          > i removed the "var", but i'm still running into the same problem -
          > newWindow is undefined and is not being close by the closeDialogWin
          > function.
          >[/color]

          It's hard to close a window that hasn't been opened.
          You're calling the close before the open (close called from onLoad).

          There was a syntax error, too.

          This worked fine in IE6.
          Note: url and form attributes changed for testing.
          Watch for word-wrap.

          <html>
          <head>
          <title>Personne l Information</title>
          <script language="javas cript" type="text/javascript">
          var newWindow=null;

          function openDialogWin()
          {
          var height = "300";
          var width = "500";
          var x = (screen.width - width) / 2;
          var y = (screen.height - height) / 2;
          var Name = window.name;

          features = "height=" + height + ",width=" + width + ",left="+ x
          + ",top=" + y;
          features +=
          ",menubar=no,re sizable=no,titl ebar=no,scrollb ars=no,status=n o,toolbar=no
          ,menubar=no,loc ation=no";
          newWindow = window.open("te st.html","newWi ndow", features);
          //alert(newWindow .name + " in openDialogWin") ;
          return;
          }

          function closeDialogWin( )
          {
          if (newWindow && !newWindow.clos ed)
          newWindow.close ();
          }
          </script>

          </head>
          <body>
          <form>
          <input type="button" name="foo" value="Open"
          onclick="openDi alogWin();">
          <input type="button" name="foo2" value="Close"
          onclick="closeD ialogWin();">

          </form>
          </body>
          </html>

          --
          --
          ~kaeli~
          You feel stuck with your debt if you can't budge it.



          Comment

          • Kevin Jones

            #6
            Re: how can i close a pop up from the parent onload

            using another button to close the window would defeat the purpose of the
            script i'm trying to write.

            here's a bit more detail about the specific problem i'm having and why i
            need this script: users are submitting a form and end up clicking the
            submit button multiple times or click on another submit out of
            frustration or impatience. i tried disabling all of the buttons on the
            page, spent 3 days on that, and decided to go with a "modal" pop up that
            would close after the parent page finished processing.

            is there another way i should be doing this that would make it clear to
            the user that they can not do anything within the application until the
            page has finished processing?

            oh yeah, was this the corrected syntax:
            "var newWindow=null; "

            jones

            *** Sent via Developersdex http://www.developersdex.com ***
            Don't just participate in USENET...get rewarded for it!

            Comment

            • kaeli

              #7
              Re: how can i close a pop up from the parent onload

              In article <40058f3e$0$703 06$75868355@new s.frii.net>,
              javajonesk@hotm ail.com enlightened us with...[color=blue]
              > using another button to close the window would defeat the purpose of the
              > script i'm trying to write.
              >[/color]

              Really?
              *ahem*

              It's for illustrative purposes.
              The point is, it works. Making the var global was just fine.
              You can close a popup from the opener. Where you put that statement is
              up to you, but trying to put it before the popup loads will result in an
              error.

              [color=blue]
              > here's a bit more detail about the specific problem i'm having and why i
              > need this script: users are submitting a form and end up clicking the
              > submit button multiple times or click on another submit out of
              > frustration or impatience. i tried disabling all of the buttons on the
              > page, spent 3 days on that, and decided to go with a "modal" pop up that
              > would close after the parent page finished processing.
              >[/color]

              Is there some flaw in your application that having a user click on
              submit more than once makes it crash?
              Or is it just that the page then submits again and the user waits
              longer, so you want a popup?
              If the former, fix it.
              If the latter, this isn't going to do you any good, since submitting a
              page clears out the old page and references to the popup window are
              lost.
              Now, if the form is posted to a NEW window, thus keeping the old window
              and code, you can close the popup when the form is done processing with
              a little convoluted code in the window that the form posted to. But I
              have a feeling that isn't what you're going for.

              If your users are on the slow side, like mine, and have only recent DOM
              browsers with javascript enabled, like mine, you can put the submit in a
              wrapper, make a variable (init to false) that is set to true when the
              submit button is clicked, then any time the button is clicked, checks
              that variable to be false before submitting.
              Note that this is not at all a good solution for general internet use.
              Very, very bad for general use. Works like a charm for intranet apps and
              other situations where you know your users and their browsers.
              [color=blue]
              >
              > oh yeah, was this the corrected syntax:
              > "var newWindow=null; "
              >[/color]

              No. Sorry, my bad - the syntax error was my fault when I took out that
              unescape and didn't remove both parens.

              --
              --
              ~kaeli~
              Who is General Failure and why is he reading my hard disk?



              Comment

              • Kevin Jones

                #8
                Re: how can i close a pop up from the parent onload

                as you can probably guess, i only dabble in javascript and primarily on
                an as-needed basis. this - submitting a page clears out the old page
                and references to the popup window are lost - is probably one of the
                most usefull bits of information that i have picked up over the last
                several days and helps make sense out of a lot of other things.

                i think i'll give this wrapper you mentioned a try and see how that
                turns out.

                -off topic: are you using a news reader or accessing this group from a
                website? if you're using a website, could you let me know what it is?
                i'm not to thrilled with using developersdex to access them.

                thanks for the help

                jones

                *** Sent via Developersdex http://www.developersdex.com ***
                Don't just participate in USENET...get rewarded for it!

                Comment

                • kaeli

                  #9
                  Re: how can i close a pop up from the parent onload

                  In article <4005a6a5$0$703 07$75868355@new s.frii.net>,
                  javajonesk@hotm ail.com enlightened us with...[color=blue]
                  > as you can probably guess, i only dabble in javascript and primarily on
                  > an as-needed basis. this - submitting a page clears out the old page
                  > and references to the popup window are lost - is probably one of the
                  > most usefull bits of information that i have picked up over the last
                  > several days and helps make sense out of a lot of other things.
                  >[/color]

                  Oh, you're welcome.
                  Sometimes the cause of a problem is totally nowhere you thought it was.
                  [color=blue]
                  > i think i'll give this wrapper you mentioned a try and see how that
                  > turns out.
                  >[/color]

                  Since you're a newbie, do you know what I meant by that?
                  If you need me to clarify, let me know.

                  I'll start you with

                  var subbed = false;
                  function mySubmit(frm)
                  {
                  if (!subbed)
                  {
                  subbed = true;
                  frm.submit();
                  }
                  else
                  {
                  alert("Please be patient.");
                  }
                  }

                  <form action="whateve r.asp" method="post" onSubmit="retur n false;">
                  <input type="button" onClick="mySubm it(this.form)">

                  Note that the onSubmit handler is NOT called when using javascript
                  form.submit(), something I am taking advantage of here to prevent going
                  around the wrapper by using the default behavior of hitting the enter
                  key when focus in ona text element. However, this makes the form
                  unusable by non-javascript-enabled browsers, so caveat emptor.
                  [color=blue]
                  > -off topic: are you using a news reader or accessing this group from a
                  > website?[/color]

                  Gravity Newsreader.
                  Sorry.

                  However, I hear there are free newsservers out there. You may want to
                  post an OT asking about it and recommendations .

                  --
                  --
                  ~kaeli~
                  When you choke a smurf, what color does it turn?



                  Comment

                  • Kevin Jones

                    #10
                    Re: how can i close a pop up from the parent onload

                    here is my final solution - and surprisingly it works! thanks to
                    everyone who viewed and replied to this thread.

                    well, i couldn't find any better solution and since i've been wracking
                    my brain over this since last wednesday, i took the easy way out and am
                    faking disabling the button. i put the original submit buttons inside of
                    a span with an id of "able" and created identical dummy buttons inside
                    of a span called "disabled". when one of the original buttons is
                    clicked, it hides "able" and displays "disabled". and since this is done
                    on the client side, the change is instant in their browser (as far as i
                    know). here is the code i used:

                    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

                    <html>
                    <head>
                    <title>Untitled </title>
                    <script language="JavaS cript">
                    function bigFake() {
                    able.style.disp lay = "none";
                    disabled.style. display = "";
                    }
                    </script>
                    </head>

                    <body>

                    <form name="formA" action="#formac tion#" method="post">
                    <span id="able">
                    <input type=submit name="btnSave" value="Save (Does Not Forward)"
                    onclick="bigFak e();"><br><br>
                    <input type=submit name="btnBack" value=" <- Back "
                    onclick="bigFak e();">&nbsp;&nb sp;&nbsp;
                    <input type=submit name="btnReturn " value="Return"
                    onclick="bigFak e();">&nbsp;&nb sp;&nbsp;
                    <input type=submit name="btnForwar d" value="Forward"
                    onclick="bigFak e();"><br><br>
                    </span>

                    <span id="disabled" style="display: none">
                    <input type=submit name="btn1" value="Save (Does Not Forward)"
                    disabled><br><b r>
                    <input type=submit name="btn2" value=" <- Back "
                    disabled>&nbsp; &nbsp;&nbsp;
                    <input type=submit name="btn3" value="Return"
                    disabled>&nbsp; &nbsp;&nbsp;
                    <input type=submit name="btn4" value="Forward" disabled><br><b r>
                    </span>
                    </form>

                    </body>
                    </html>


                    jones

                    *** Sent via Developersdex http://www.developersdex.com ***
                    Don't just participate in USENET...get rewarded for it!

                    Comment

                    • Randy Webb

                      #11
                      Re: how can i close a pop up from the parent onload

                      Kevin Jones wrote:
                      [color=blue]
                      > here is my final solution - and surprisingly it works! thanks to
                      > everyone who viewed and replied to this thread.
                      >
                      > well, i couldn't find any better solution and since i've been wracking
                      > my brain over this since last wednesday, i took the easy way out and am
                      > faking disabling the button. i put the original submit buttons inside of
                      > a span with an id of "able" and created identical dummy buttons inside
                      > of a span called "disabled". when one of the original buttons is
                      > clicked, it hides "able" and displays "disabled". and since this is done
                      > on the client side, the change is instant in their browser (as far as i
                      > know). here is the code i used:
                      >
                      > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                      >
                      > <html>
                      > <head>
                      > <title>Untitled </title>
                      > <script language="JavaS cript">
                      > function bigFake() {
                      > able.style.disp lay = "none";
                      > disabled.style. display = "";
                      > }
                      > </script>[/color]


                      you should test that in something besides IE....

                      --
                      Randy

                      Comment

                      • kaeli

                        #12
                        Re: how can i close a pop up from the parent onload

                        In article <40082b35$0$703 00$75868355@new s.frii.net>,
                        javajonesk@hotm ail.com enlightened us with...[color=blue]
                        >
                        > <html>
                        > <head>
                        > <title>Untitled </title>
                        > <script language="JavaS cript">
                        > function bigFake() {
                        > able.style.disp lay = "none";
                        > disabled.style. display = "";
                        > }
                        > </script>
                        > </head>
                        >[/color]

                        This will fail in NN/Moz.
                        You forgot document.getEle mentById("able" ) syntax is required in non-IE
                        browsers. Only IE knows that shortcut you used.
                        NN says "able is not defined".

                        --
                        --
                        ~kaeli~
                        A man's home is his castle..., in a manor of speaking.



                        Comment

                        Working...