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.
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
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??
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
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
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
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?
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
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
> 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
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
I do not enough practice English to explain my desagrement.
But possibly I didn't see what exactly you wanted to say ?
--
sm
Yes. I fully agree with you on this.
>
> >> 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).
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
- by just plain text or custom icon (best)
- by using title attribute (excellent)
- a custom cursor (good)
<a href="[URL]" target="ProductDescription" 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
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/docs/DOM:window.open#Always_identify_links_which_will_create_.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>
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
He lost the right click of his mouse?
--
sm