window.open

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

    window.open

    hi,

    i have a page calendar.aspx which returns selected date i.e
    window.returnVa lue=selectedDat e; window.close(); it works fine with IE
    but not for Firefox.

    i tried window.opener.d ocument.getElem entById(<%=txth idden.ClientID
    %>").value=sele ctedDate; where window.opener is pageA.aspx

    but am confused bkoz many pages r using this calendar.aspx page and it
    is not a good way to have a txthidden in all pages.

    i tried to use a global variable that is not working.bkoz the caller
    function is in a separate js file and is being used in pageA.aspx.

    any other way??

    thx.
  • SAM

    #2
    Re: window.open

    CreativeMind a écrit :
    hi,
    >
    i have a page calendar.aspx which returns selected date i.e
    window.returnVa lue=selectedDat e; window.close(); it works fine with IE
    but not for Firefox.
    >
    i tried window.opener.d ocument.getElem entById(<%=txth idden.ClientID
    %>").value=sele ctedDate; where window.opener is pageA.aspx
    window.opener is certainly not a page ;-)
    ^^^^^^
    Are you sure that your element ( <%=txthidden.Cl ientID %)
    has an *ID* ? (with this name) ?

    opener.document .myForm.myEleme nt.value = selectedDate;
    self.close();

    where 'myForm" is the *name* of the form (in mother window)
    and 'myElement' is the *name* of your input tag

    i tried to use a global variable that is not working.bkoz the caller
    what does mean 'bkoz' ? german idiom ?
    function is in a separate js file and is being used in pageA.aspx.
    And you can't call this variable from your popup ?

    opener.myVariab le = selectedDate;

    --
    sm

    Comment

    • CreativeMind

      #3
      Re: window.open

      thx for reply.
      actually javascript code working behind calendar.aspx is
      window.returnVa lue=selectedVal ue; window.close();

      and on myJS.js that is being used on pageA.aspx has code
      vReturn = window.open("ht tp://calendar.aspx", "","Width:246px ,Height:
      150px, status: 1, location: 1;" ); debugger;
      my goal is to take the value in vReturn so that i can use it to fill a
      textbox.

      but window.open is not assigning value to vReturn in case of Ff. how
      can i do that??

      Comment

      • SAM

        #4
        Re: window.open

        CreativeMind a écrit :
        thx for reply.
        actually javascript code working behind calendar.aspx is
        window.returnVa lue=selectedVal ue; window.close();
        >
        and on myJS.js that is being used on pageA.aspx has code
        vReturn = window.open("ht tp://calendar.aspx", "","Width:246px ,Height:
        150px, status: 1, location: 1;" ); debugger;
        my goal is to take the value in vReturn so that i can use it to fill a
        textbox.
        it is very simple and has been given, you don't "take from" the popup,
        i(s him who send to his mother the value.

        In your popup (the file in your popup) you code :

        opener.document .forms[0].returnValue.va lue = selectedDate;

        where 'returnValue' is the name of your text-field.
        (and presuming you have only one form in your pageA.aspx)

        You can also have a function in the JS of pageA.aspx :

        function getPopupDate() {
        if(typeof vReturn != 'undefined' && !vReturn.closed )
        {
        if(typeof vReturn.selecte dDate == 'undefined' ||
        vReturn.selecte dDate == '')
        {
        alert('no selected date');
        return;
        }
        document.forms[0].returnValue.va lue = vReturn.selecte dDate;
        vReturn.close() ;
        }
        else alert('No opened popup vReturn');
        }

        and in the file of the popup :

        <button onclick="opener .getPopupDate() ;"OK </button>

        but window.open is not assigning value to vReturn in case of Ff. how
        can i do that??
        vReturn = window.open("ht tp://calendar ... etc )

        means that the new opened window (the popup) is named 'vReturn'

        So, I think if you do from your popup (named 'vReturn')

        opener.vReturn = dateFoo;

        it's probably equal to give a new name to your PopUp


        About window.open() :
        <http://developer.mozil la.org/en/docs/DOM:window.open >
        and 'opener' :
        <http://developer.mozil la.org/en/docs/window.opener>

        --
        sm

        Comment

        • GTalbot

          #5
          Re: window.open

          On Jul 11, 2:11 pm, CreativeMind <aftab.pu...@gm ail.comwrote:
          thx for reply.
          actually javascript code working behind calendar.aspx is
          window.returnVa lue=selectedVal ue; window.close();
          >
          Creative,

          You repeated what you first said in your original post. You have not
          given us the useful specifics, helpful details which we may be needing
          to examine.

          Every post asking for coding assistance should start with an URL. A
          very limited code chunk may not help figure out the issue. You want
          help, assistance? Then try to provide a post as helpful as possible.

          Also, you could identify the version of browsers involved. It works in
          IE... but which versions of IE? It does not work in Firefox but again
          which versions of Firefox? Again, such details are often important.
          and on myJS.js that is being used on pageA.aspx has code
            vReturn =     window.open("ht tp://calendar.aspx", "","Width:246px ,Height:
          150px,  status: 1,   location: 1;" ); debugger;
          There should be no blank space in the 3rd parameter of the window.open
          call.

          "strWindowFeatu res
          This string parameter must not contain any blank space."
          The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.


          Second, an empty strWindowName is not recommendable.

          "Always use a target attribute"
          The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.


          Third, consult the examples at
          <http://developer.mozil la.org/en/docs/DOM:window.open >
          to see/know how to construct the string of the 3rd parameter.

          vReturn = window.open("ht tp://calendar.aspx", "CalendarWindow Name",
          "width=246,heig ht=150,status=y es,location=yes ,resizable=yes, scrollbars=yes" );
          my goal is to take the value in vReturn so that i can use it to fill a
          textbox.
          No URL.

          Gérard

          Comment

          • CreativeMind

            #6
            Re: window.open

            ----------------------
            pageA.aspx
            <script language="javas cript" src="../Calendar/Calendar.js"></
            script>
            <asp:textbox id="txtCompleti onDate" runat="server"
            CssClass="clDat eTextBox" Width="80px" Wrap="False"></asp:textbox>
            ----------------------
            calendar.js

            if (navigator.appN ame=="Netscape" ) {
            var refToWindow;
            refToWindow =window.open(To Call,"","Width: 246px,Height:24 3px,status:
            1,location:1;mo dal=yes" );
            self.close();
            }

            ------------------------
            if (navigator.appN ame=="Netscape" ){
            if(window.opene r && !window.closed) {

            window.opener.d ocument.forms[0].getElementById ("_ctl0_Content PlaceHolder2_tx tCompletionDate ").value=Select edDate;
            window.close();
            }

            }
            ----------------------------
            this given value is not being assigned txtCompletionDa te.
            SelectedDate="0 1/01/2008"
            here is the problem.
            window.opener.d ocument.forms[0].getElementById ("_ctl0_Content PlaceHolder2_tx tCompletionDate ").value=select edDate

            -----------------------------

            Comment

            • CreativeMind

              #7
              Re: window.open

              On Jul 14, 6:20 pm, CreativeMind <aftab.pu...@gm ail.comwrote:
              ----------------------
              pageA.aspx
              <script language="javas cript" src="../Calendar/Calendar.js"></
              script>
              <asp:textbox id="txtCompleti onDate" runat="server"
              CssClass="clDat eTextBox" Width="80px" Wrap="False"></asp:textbox>
              ----------------------
              calendar.js
              >
              if (navigator.appN ame=="Netscape" ) {
              var refToWindow;
              refToWindow =window.open(To Call,"","Width: 246px,Height:24 3px,status:
              1,location:1;mo dal=yes" );
              self.close();
              >
              }
              >
              ------------------------
              if (navigator.appN ame=="Netscape" ){
              if(window.opene r && !window.closed) {
              >
              window.opener.d ocument.forms[0].getElementById ("_ctl0_Content PlaceHolder2_tx tCompletionDate ").value=Select edDate;
              window.close();
              }
              >
              }
              ----------------------------
              this given value is not being assigned txtCompletionDa te.
              SelectedDate="0 1/01/2008"
              here is the problem.
              window.opener.d ocument.forms[0].getElementById ("_ctl0_Content PlaceHolder2_tx tCompletionDate ").value=select edDate
              >
              -----------------------------
              thx a lot ....
              i made correction in syntax, now it's working..
              correct syntax after removing forms[0] is
              window.opener.d ocument.getElem entById.
              once again thx

              Comment

              • CreativeMind

                #8
                Re: window.open

                any idea plz..
                i did that for only one control.
                but
                if many controls likes txt1..txt9 from different pages are calling to
                this calendar.aspx page , i think to put a check on window.opener to
                know about page. like

                if (window.opener= =pageA.aspx)

                window.opener.d ocument.getElem entById('_ctl0_ txt1).value=sel ectedDate;

                now..question is how to differentiate controls. which control is
                requesting the selectedDate?

                Comment

                • SAM

                  #9
                  Re: window.open

                  CreativeMind a écrit :
                  ----------------------
                  pageA.aspx
                  <script language="javas cript" src="../Calendar/Calendar.js"></
                  script>
                  <asp:textbox id="txtCompleti onDate" runat="server"
                  CssClass="clDat eTextBox" Width="80px" Wrap="False"></asp:textbox>
                  ----------------------
                  calendar.js
                  >
                  if (navigator.appN ame=="Netscape" ) {
                  Why 'if(Netscape)' ?
                  var refToWindow;
                  no !

                  var refToWindow = window.open( blah );
                  refToWindow =window.open(To Call,"","Width: 246px,Height:24 3px,status:
                  1,location:1;mo dal=yes" );
                  Please no uppercase for the attributes between () and no unity (px),
                  once more it is not ';' but ','
                  and it is not more ':' but '='

                  You are doing a pretty mix between CSS and JavaScript :-(

                  var refToWindow = window.open(ToC all,"",
                  "width=246,heig ht=243,status=1 ,location=1,mod al=yes");

                  and Netscape is not IE who does like you a lot of ugly mixes

                  modal is an attribute for IE what does it do there ?
                  (if the popup is for Netscape)

                  what is this 'ToCall' ?
                  self.close();
                  Hu ? ? ? you want to close the mother, the opener ! ? ????

                  How do you expect to reach it to send it your 'SelectedDate' ?

                  }
                  >
                  ------------------------
                  if (navigator.appN ame=="Netscape" ){
                  if(window.opene r && !window.closed) {
                  >
                  window.opener.d ocument.forms[0].getElementById ("_ctl0_Content PlaceHolder2_tx tCompletionDate ").value='Selec tedDate' ?
                  ;
                  window.close();
                  OK, this time you can close this window
                  because it has been opened by JavaScript.
                  I think the mother (where pageA.aspx is) was not opened by JS, it is
                  probably why 'calendar.js' doesn't close it. Chance or luck ?
                  }
                  >
                  }
                  ----------------------------
                  this given value is not being assigned txtCompletionDa te.
                  SelectedDate="0 1/01/2008"
                  here is the problem.
                  window.opener.d ocument.forms[0].getElementById ("_ctl0_Content PlaceHolder2_tx tCompletionDate ").value=select edDate
                  >
                  Is there a form in this pageA.aspx ?
                  (not seen in your digest)
                  and only one ?

                  If really you pass by a popup that launches the calendar's popup
                  perhaps could you try :

                  opener.opener.d ocument.forms[]. ... etc ...

                  but if the mother (intermediary popup) has been closed,
                  not sure that will find the grand mother ?

                  I see in pageA that the text-field has an ID named 'txtCompletionD ate' so
                  why do you want to feed '_ctl0_ContentP laceHolder2_txt CompletionDate' ?

                  Code of this '_ctl0_ContentP laceHolder2_txt CompletionDate' please.

                  --
                  sm

                  Comment

                  • SAM

                    #10
                    Re: window.open

                    CreativeMind a écrit :
                    any idea plz..
                    impossible to know to what you're answering
                    i did that for only one control.
                    but
                    if many controls likes txt1..txt9 from different pages are calling to
                    this calendar.aspx page , i think to put a check on window.opener to
                    know about page. like
                    >
                    if (window.opener= =pageA.aspx)
                    ??? ça ne veut rien dire.

                    if (opener.locatio n.toSring().ind exOf('pageA')>0 ) { alert('OK'); }

                    window.opener.d ocument.getElem entById('_ctl0_ txt1).value=sel ectedDate;
                    >
                    now..question is how to differentiate controls. which control is
                    requesting the selectedDate?
                    By 'control' you mean 'textfield' ?
                    or (submit) button ?

                    HTML :
                    ======
                    <p><input type="text" id="date_1" name="date_1">
                    <input type=button name="controler _1" value="help date"
                    onclick="pop(th is)">
                    <p><input type="text" id="date_2" name="date_2">
                    <input type=button name="controler _2" value="help date"
                    onclick="pop(th is)">

                    JS :
                    =====
                    function pop(what) {
                    what = what.name.split ('_')[1]; // get the number
                    if(typeof refDatePopup == 'undefined' || refDatePopup.cl osed)
                    refDatePopup = window.open('', '','width=424,h eight=327');
                    refDatePopup.lo cation = 'calendar.asp?c ontrol=date_'+w hat;
                    refDatePopup.fo cus();
                    }

                    JS of 'calendar.asp' :
                    =============== =======

                    opener.document .getElementById ('<%= $control %>').value = selectedDate;

                    --
                    sm

                    Comment

                    • GTalbot

                      #11
                      Re: window.open

                      On Jul 14, 5:48 pm, SAM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
                      wrote:

                      JS :
                      =====
                      function pop(what) {
                      what = what.name.split ('_')[1];  // get the number
                      if(typeof refDatePopup == 'undefined' || refDatePopup.cl osed)
                      refDatePopup = window.open('', '','width=424,h eight=327');
                      The previous line instruction is possibly executable but I have always
                      found such quite questionable, debatable.
                      refDatePopup.fo cus();
                      This is not needed if typeof refDatePopup == 'undefined' is true or if
                      refDatePopup.cl osed is true. If the window object reference does not
                      exist or the referenced window no longer exists, then a new secondary
                      window will need to be created, will be created and it will take
                      system focus on top of opener without any need for
                      refDatePopup.fo cus().

                      Regards, Gérard

                      Comment

                      • Thomas 'PointedEars' Lahn

                        #12
                        Re: window.open

                        GTalbot wrote:
                        SAM wrote:
                        >refDatePopup = window.open('', '','width=424,h eight=327');
                        >
                        The previous line instruction is possibly executable but I have always
                        found such quite questionable, debatable.
                        True, the `scrollbars' and `resizable' features should be requested as well.
                        >refDatePopup.f ocus();
                        >
                        This is not needed if typeof refDatePopup == 'undefined' is true or if
                        refDatePopup.cl osed is true. If the window object reference does not
                        exist or the referenced window no longer exists, then a new secondary
                        window will need to be created, will be created and it will take
                        system focus on top of opener without any need for
                        refDatePopup.fo cus().
                        If the window/tab with the name (second argument) exists, while its content
                        is going to change, it is _not_ going to be focused automatically.


                        PointedEars
                        --
                        Anyone who slaps a 'this page is best viewed with Browser X' label on
                        a Web page appears to be yearning for the bad old days, before the Web,
                        when you had very little chance of reading a document written on another
                        computer, another word processor, or another network. -- Tim Berners-Lee

                        Comment

                        • SAM

                          #13
                          Re: window.open

                          GTalbot a écrit :
                          On Jul 14, 5:48 pm, SAM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
                          wrote:
                          >
                          >
                          >JS :
                          >=====
                          >function pop(what) {
                          >what = what.name.split ('_')[1]; // get the number
                          >if(typeof refDatePopup == 'undefined' || refDatePopup.cl osed)
                          >refDatePopup = window.open('', '','width=424,h eight=327');
                          >
                          The previous line instruction is possibly executable but I have always
                          found such quite questionable, debatable.
                          >
                          >refDatePopup.f ocus();
                          >
                          This is not needed if typeof refDatePopup == 'undefined' is true or if
                          refDatePopup.cl osed is true. If the window object reference does not
                          exist or the referenced window no longer exists, then a new secondary
                          window will need to be created, will be created and it will take
                          system focus on top of opener without any need for
                          refDatePopup.fo cus().
                          I do not enough practice English to explain my desagrement.

                          But possibly I didn't see what exactly you wanted to say ?

                          --
                          sm

                          Comment

                          • GTalbot

                            #14
                            Re: window.open

                            On Jul 15, 4:19 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                            wrote:
                            GTalbot wrote:
                            SAM wrote:
                            refDatePopup = window.open('', '','width=424,h eight=327');
                            >
                            The previous line instruction is possibly executable but I have always
                            found such quite questionable, debatable.
                            >
                            True, the `scrollbars' and `resizable' features should be requested as well.

                            Yes. I fully agree with you on this.
                            >
                            refDatePopup.fo cus();
                            >
                            This is not needed if typeof refDatePopup == 'undefined' is true orif
                            refDatePopup.cl osed is true. If the window object reference does not
                            exist or the referenced window no longer exists, then a new secondary
                            window will need to be created, will be created and it will take
                            system focus on top of opener without any need for
                            refDatePopup.fo cus().
                            >
                            If the window/tab with the name (second argument) exists, while its content
                            is going to change, it is _not_ going to be focused automatically.
                            A refDatePopup object reference implies a successful window.open
                            execution, therefore a script initiated secondary window (or tab).

                            The important issue is if the window exists and if it has not been
                            closed. If it's minimized or behind the opener, then it can be placed
                            on top of the opener. The need to focus() is only relevant if the
                            window already exists and has not been closed.

                            If a window/tab with a name exists, then the issue is how to verify
                            its live/current existence first... justifying a focus() command to
                            bring it on top.

                            A non-script-initiated window/tab created by a mere
                            target="SomeWin dowName" can not and will not be focusable by
                            javascript anyway.

                            That's why it's always recommended and recommendable to indicate to
                            the user/visitor that a link opens up a new window with the proposed/
                            suggested possible tips/hints at

                            The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.


                            - by just plain text or custom icon (best)
                            - by using title attribute (excellent)
                            - a custom cursor (good)

                            <a href="[URL]" target="Product Description" title="This link will
                            create a new window or will reuse an already opened one"
                            onclick="[script function opening new window;] return false;">

                            Gérard

                            Comment

                            • Thomas 'PointedEars' Lahn

                              #15
                              Re: window.open

                              GTalbot wrote:
                              Thomas 'PointedEars' Lahn wrote:
                              >GTalbot wrote:
                              >>SAM wrote:
                              >>>refDatePop up = window.open('', '','width=424,h eight=327');
                              >>[...]
                              >>>refDatePopup .focus();
                              >>This is not needed if typeof refDatePopup == 'undefined' is true or if
                              >>refDatePopup. closed is true. If the window object reference does not
                              >>exist or the referenced window no longer exists, then a new secondary
                              >>window will need to be created, will be created and it will take
                              >>system focus on top of opener without any need for
                              >>refDatePopup. focus().
                              >If the window/tab with the name (second argument) exists, while its content
                              >is going to change, it is _not_ going to be focused automatically.
                              >
                              A refDatePopup object reference implies a successful window.open
                              execution, therefore a script initiated secondary window (or tab).
                              But that tested reference is discarded after the following window.open()
                              call due to the assignment. Therefore, another feature test must be added
                              before the new reference can be safely used. However, if we assume that the
                              reference is always valid (which does not need to be the case, considering
                              popup blockers), it may be that the window with that name already existed,
                              and then it is reused and not (always) automatically focused.
                              The important issue is if the window exists and if it has not been
                              closed. If it's minimized or behind the opener, then it can be placed
                              on top of the opener. The need to focus() is only relevant if the
                              window already exists and has not been closed.
                              Which is entirely possible even if there was no valid user-defined reference
                              to the corresponding Window object before before the window.open() call.
                              The existence of the window is not defined by its its Window object being
                              referred to previously.
                              If a window/tab with a name exists, then the issue is how to verify
                              its live/current existence first... justifying a focus() command to
                              bring it on top.
                              After a runtime feature test, of course.
                              A non-script-initiated window/tab created by a mere
                              target="SomeWin dowName" can not and will not be focusable by
                              javascript anyway.
                              True. However, if it is addressed in a window.open() call, it can receive
                              the focus programmaticall y.
                              That's why it's always recommended and recommendable to indicate to
                              the user/visitor that a link opens up a new window with the proposed/
                              suggested possible tips/hints at
                              >
                              The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.

                              [...]
                              No argument there. However, it is even better to leave the choice to the user.


                              PointedEars
                              --
                              Use any version of Microsoft Frontpage to create your site.
                              (This won't prevent people from viewing your source, but no one
                              will want to steal it.)
                              -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

                              Comment

                              Working...