window.open

Discussion in 'Javascript' started by CreativeMind, Jul 11, 2008.

  1. CreativeMind

    CreativeMind Guest

    hi,

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

    i tried window.opener.document.getElementById(<%=txthidden.ClientID
    %>").value=selectedDate; 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.
    CreativeMind, Jul 11, 2008
    #1
    1. Advertising

  2. CreativeMind

    SAM Guest

    CreativeMind a écrit :
    > hi,
    >
    > i have a page calendar.aspx which returns selected date i.e
    > window.returnValue=selectedDate; window.close(); it works fine with IE
    > but not for Firefox.
    >
    > i tried window.opener.document.getElementById(<%=txthidden.ClientID
    > %>").value=selectedDate; where window.opener is pageA.aspx


    window.opener is certainly not a page ;-)
    ^^^^^^
    Are you sure that your element ( <%=txthidden.ClientID %> )
    has an *ID* ? (with this name) ?

    opener.document.myForm.myElement.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.myVariable = selectedDate;

    --
    sm
    SAM, Jul 11, 2008
    #2
    1. Advertising

  3. CreativeMind

    CreativeMind Guest

    thx for reply.
    actually javascript code working behind calendar.aspx is
    window.returnValue=selectedValue; window.close();

    and on myJS.js that is being used on pageA.aspx has code
    vReturn = window.open("http://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??
    CreativeMind, Jul 11, 2008
    #3
  4. CreativeMind

    SAM Guest

    CreativeMind a écrit :
    > thx for reply.
    > actually javascript code working behind calendar.aspx is
    > window.returnValue=selectedValue; window.close();
    >
    > and on myJS.js that is being used on pageA.aspx has code
    > vReturn = window.open("http://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.value = 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.selectedDate == 'undefined' ||
    vReturn.selectedDate == '')
    {
    alert('no selected date');
    return;
    }
    document.forms[0].returnValue.value = vReturn.selectedDate;
    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("http://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.mozilla.org/en/docs/DOM:window.open>
    and 'opener' :
    <http://developer.mozilla.org/en/docs/window.opener>

    --
    sm
    SAM, Jul 11, 2008
    #4
  5. CreativeMind

    GTalbot Guest

    On Jul 11, 2:11 pm, CreativeMind <> wrote:
    > thx for reply.
    > actually javascript code working behind calendar.aspx is
    > window.returnValue=selectedValue; 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("http://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.

    "strWindowFeatures
    This string parameter must not contain any blank space."
    http://developer.mozilla.org/en/docs/DOM:window.open#Return_value_and_parameters

    Second, an empty strWindowName is not recommendable.

    "Always use a target attribute"
    http://developer.mozilla.org/en/docs/DOM:window.open#Always_use_the_target_attribute

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

    vReturn = window.open("http://calendar.aspx", "CalendarWindowName",
    "width=246,height=150,status=yes,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
    GTalbot, Jul 13, 2008
    #5
  6. CreativeMind

    CreativeMind Guest

    ----------------------
    pageA.aspx
    <script language="javascript" src="../Calendar/Calendar.js"></
    script>
    <asp:textbox id="txtCompletionDate" runat="server"
    CssClass="clDateTextBox" Width="80px" Wrap="False"></asp:textbox>
    ----------------------
    calendar.js

    if (navigator.appName=="Netscape") {
    var refToWindow;
    refToWindow =window.open(ToCall,"","Width:246px,Height:243px,status:
    1,location:1;modal=yes" );
    self.close();
    }

    ------------------------
    if (navigator.appName=="Netscape"){
    if(window.opener && !window.closed){

    window.opener.document.forms[0].getElementById("_ctl0_ContentPlaceHolder2_txtCompletionDate").value=SelectedDate;
    window.close();
    }

    }
    ----------------------------
    this given value is not being assigned txtCompletionDate.
    SelectedDate="01/01/2008"
    here is the problem.
    window.opener.document.forms[0].getElementById("_ctl0_ContentPlaceHolder2_txtCompletionDate").value=selectedDate

    -----------------------------
    CreativeMind, Jul 14, 2008
    #6
  7. CreativeMind

    CreativeMind Guest

    On Jul 14, 6:20 pm, CreativeMind <> wrote:
    > ----------------------
    > pageA.aspx
    > <script language="javascript" src="../Calendar/Calendar.js"></
    > script>
    > <asp:textbox id="txtCompletionDate" runat="server"
    > CssClass="clDateTextBox" Width="80px" Wrap="False"></asp:textbox>
    > ----------------------
    > calendar.js
    >
    > if (navigator.appName=="Netscape") {
    > var refToWindow;
    > refToWindow =window.open(ToCall,"","Width:246px,Height:243px,status:
    > 1,location:1;modal=yes" );
    > self.close();
    >
    > }
    >
    > ------------------------
    > if (navigator.appName=="Netscape"){
    > if(window.opener && !window.closed){
    >
    > window.opener.document.forms[0].getElementById("_ctl0_ContentPlaceHolder2_txtCompletionDate").value=SelectedDate;
    > window.close();
    > }
    >
    > }
    > ----------------------------
    > this given value is not being assigned txtCompletionDate.
    > SelectedDate="01/01/2008"
    > here is the problem.
    > window.opener.document.forms[0].getElementById("_ctl0_ContentPlaceHolder2_txtCompletionDate").value=selectedDate
    >
    > -----------------------------


    thx a lot ....
    i made correction in syntax, now it's working..
    correct syntax after removing forms[0] is
    window.opener.document.getElementById.
    once again thx
    CreativeMind, Jul 14, 2008
    #7
  8. CreativeMind

    CreativeMind Guest

    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.document.getElementById('_ctl0_txt1).value=selectedDate;

    now..question is how to differentiate controls. which control is
    requesting the selectedDate?
    CreativeMind, Jul 14, 2008
    #8
  9. CreativeMind

    SAM Guest

    CreativeMind a écrit :
    > ----------------------
    > pageA.aspx
    > <script language="javascript" src="../Calendar/Calendar.js"></
    > script>
    > <asp:textbox id="txtCompletionDate" runat="server"
    > CssClass="clDateTextBox" Width="80px" Wrap="False"></asp:textbox>
    > ----------------------
    > calendar.js
    >
    > if (navigator.appName=="Netscape") {


    Why 'if(Netscape)' ?

    > var refToWindow;


    no !

    var refToWindow = window.open( blah );

    > refToWindow =window.open(ToCall,"","Width:246px,Height:243px,status:
    > 1,location:1;modal=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(ToCall,"",
    "width=246,height=243,status=1,location=1,modal=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.appName=="Netscape"){
    > if(window.opener && !window.closed){
    >
    > window.opener.document.forms[0].getElementById("_ctl0_ContentPlaceHolder2_txtCompletionDate").value='SelectedDate' ?


    ;
    > 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 txtCompletionDate.
    > SelectedDate="01/01/2008"
    > here is the problem.
    > window.opener.document.forms[0].getElementById("_ctl0_ContentPlaceHolder2_txtCompletionDate").value=selectedDate
    >


    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.document.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 'txtCompletionDate' so
    why do you want to feed '_ctl0_ContentPlaceHolder2_txtCompletionDate' ?

    Code of this '_ctl0_ContentPlaceHolder2_txtCompletionDate' please.

    --
    sm
    SAM, Jul 14, 2008
    #9
  10. CreativeMind

    SAM Guest

    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.location.toSring().indexOf('pageA')>0) { alert('OK'); }


    > window.opener.document.getElementById('_ctl0_txt1).value=selectedDate;
    >
    > 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(this)">
    <p><input type="text" id="date_2" name="date_2">
    <input type=button name="controler_2" value="help date"
    onclick="pop(this)">

    JS :
    =====
    function pop(what) {
    what = what.name.split('_')[1]; // get the number
    if(typeof refDatePopup == 'undefined' || refDatePopup.closed)
    refDatePopup = window.open('','','width=424,height=327');
    refDatePopup.location = 'calendar.asp?control=date_'+what;
    refDatePopup.focus();
    }

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

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

    --
    sm
    SAM, Jul 14, 2008
    #10
  11. CreativeMind

    GTalbot Guest

    On Jul 14, 5:48 pm, SAM <>
    wrote:


    > JS :
    > =====
    > function pop(what) {
    > what = what.name.split('_')[1];  // get the number
    > if(typeof refDatePopup == 'undefined' || refDatePopup.closed)
    > refDatePopup = window.open('','','width=424,height=327');


    The previous line instruction is possibly executable but I have always
    found such quite questionable, debatable.

    > 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().

    Regards, Gérard
    GTalbot, Jul 15, 2008
    #11
  12. GTalbot wrote:
    > SAM wrote:
    >> refDatePopup = window.open('','','width=424,height=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.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.


    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
    Thomas 'PointedEars' Lahn, Jul 15, 2008
    #12
  13. CreativeMind

    SAM Guest

    GTalbot a écrit :
    > On Jul 14, 5:48 pm, SAM <>
    > wrote:
    >
    >
    >> JS :
    >> =====
    >> function pop(what) {
    >> what = what.name.split('_')[1]; // get the number
    >> if(typeof refDatePopup == 'undefined' || refDatePopup.closed)
    >> refDatePopup = window.open('','','width=424,height=327');

    >
    > The previous line instruction is possibly executable but I have always
    > found such quite questionable, debatable.
    >
    >> 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().


    I do not enough practice English to explain my desagrement.

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

    --
    sm
    SAM, Jul 15, 2008
    #13
  14. CreativeMind

    GTalbot Guest

    On Jul 15, 4:19 pm, Thomas 'PointedEars' Lahn <>
    wrote:
    > GTalbot wrote:
    > > SAM wrote:
    > >> refDatePopup = window.open('','','width=424,height=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.focus();

    >
    > > This is not needed if typeof refDatePopup == 'undefined' is true orif
    > > 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).

    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="SomeWindowName" 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

    http://developer.mozilla.org/en/doc...28or_will_re-use.29_a_new.2C_secondary_window

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

    <a href="" target="ProductDescription" title... opening new window;] return false;"> Gérard
    GTalbot, Jul 15, 2008
    #14
  15. GTalbot wrote:
    > Thomas 'PointedEars' Lahn wrote:
    >> GTalbot wrote:
    >>> SAM wrote:
    >>>> refDatePopup = window.open('','','width=424,height=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="SomeWindowName" 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 programmatically.

    > 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
    >
    > http://developer.mozilla.org/en/doc...28or_will_re-use.29_a_new.2C_secondary_window
    > [...]


    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>
    Thomas 'PointedEars' Lahn, Jul 15, 2008
    #15
  16. CreativeMind

    SAM Guest

    Thomas 'PointedEars' Lahn a écrit :
    > GTalbot wrote:
    >> SAM wrote:
    >>> refDatePopup = window.open('','','width=424,height=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.


    on s'en fout, c'est un exemple, il n'a pas à être complet, et de toutes
    façons ça satisfait Netscape 4, alors ...

    >>> 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.


    Voilà! j'allais le dire.

    --
    sm
    SAM, Jul 16, 2008
    #16
  17. CreativeMind

    SAM Guest

    Thomas 'PointedEars' Lahn a écrit :
    >
    > However, it is even better to leave the choice to the user.


    He lost the right click of his mouse?

    --
    sm
    SAM, Jul 16, 2008
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ml
    Replies:
    0
    Views:
    1,446
  2. ml
    Replies:
    2
    Views:
    4,844
    John C. Bollinger
    Nov 30, 2004
  3. wax
    Replies:
    9
    Views:
    333
  4. Clare Hsiao
    Replies:
    11
    Views:
    257
    Michael Winter
    Feb 13, 2004
  5. PC HUA
    Replies:
    2
    Views:
    404
    PC HUA
    May 19, 2004
Loading...

Share This Page