Accessing windows.opener.document when using a yearly calendar widget

Accessing windows.opener.document when using a yearly calendar widget

Gentelmen (and Ladies)...

I've got an interesting dilema...

I'm trying to edit multiple dates in a table record using a calendar widget.

I'm using a pop up window with the calendar in flat style mode since I can not use a web block inside a table record.

This should be quite strait forward, set up a simple window with the yearly calendar widget in flat style mode, pass the id of the inputbox in the original window and use window.opener.document.getElementById('xxx').value=zzz to write the value.

The interesting bit is that as soon as I paste a yearlycalendar widget in the form by some "obscure" reason it gives me the javascript error: "window.opener.document is null or not an object"

It seams that by using the flatstyle=true somehow the window.opener.document is destroyed.

Has anyone solve this issue or has anyone found an "elegant" way to edit dates in a table record.


Rui Barbosa
Hi Rui

I'd say the problem is related with the YearlyCalendar webblock's javascript. It has the following two lines at the top:
var close = '';
var opener = '';

This changes (redefines) the original close and opener objects on the window.

One way to solve this with minimal changes to the YearlyCalendar's javascript would be to add the following two lines at the top:
var windowOpener = window.opener;
var windowClose = window.close;

Now, your script should be changed to:


(note: you also had a mistake in the input name, as it is case sensitive: 'wtedit2')

If you have the time, you could try to fix it in a more proper way and submit the fix. Anyway, I'm not sure if this component is the most appropriate to be used. Have you tried the WidgetLibrary's Calendar web block? Maybe someone more experienced than myself on these components could advise you.

I hope this helps you.

António Melo

Hello António,

First of all thanks for your input.

I tryed your sugestion but had the same result.

I do not know much about Java Script but i think that objects are passed has a reference and when the window.opener is destroyed the windowOpener is also destroyed (is there a method to clone objects in java script?)

I took a look at the code from the yearlyCalendar and i still could not find where the object is destroyed.

this piece of code
if (p_newwindow == false){
close = '';
opener = '';
self_opener = '';
} else {
close = 'window.close();';
opener = 'window.opener.';
self_opener = 'self.opener.';
is part of the build method , show_calendar and show yearly calender and unless sometimes the p_newwindow is true and other is false the opener='' just by it self should not produce this effect...

Maybe i'm looking in the wrong place...

About the "normal" calendar, there is another problem. That calendar does not implement the next function when clicked, so it makes very hard to execute a peace of code when the user clicks without changing the calendar code (what event should i use? onChange does not work)...

On the other hand it could be easier to implemet that method in calendar, i'm open to sugestions...

Again thanks a lot for you contribution!



Hi Rui

The changes I suggested were first tested. The "Ola" value was displayed in both inputs. But my default browser is Firefox. Could you please try to use that browser, just to check that you are using the suggested changes?

After reading your post, I tried using IE 7 (just in case). And it fails with that browser, so this solution probably doesn't fit your needs. The best solution would probably be to refactor the code you mentioned.

António Melo
Yes I checked and it does work in FireFox...

Thanks again
Hi Rui

I've renamed both variables, so now we've:
var v_close = '';
var v_opener = '';

I've also renamed all the variable references to match these new names. Now your onclick event script may be written as expected:

I've tried your sample in Firefox 2 and in IE 7 and it seems it is working. You may find both omls in the attached .zip file.
Please note that I haven't tested the changed YearlyCalendarWidget in any other scenarios.

I hope this solves your problem.

António Melo

I've also fixed a problem with Firefox, related with the month navigation links (they weren't being displayed). Now they should appear.

I've done some tests using the sample that is enclosed in the solution. By the way, I've used Service Studio 4.1.3.

I've also submitted these changes to the solution owner for his/her appreciation. This means that in the future a newer version of this solution may be published in the Solutions area.
António Melo

Many thanks!!!

Sorry for taking so long to answer.

I have tested it and will incorporate changes in my yearlyCalendar.