Click to See Complete Forum and Search --> : "object doesn't support this property or method" error


Jen Song
11-06-2003, 10:14 AM
Hi,

I have the following javascript and HTML:

.............
<head>

<SCRIPT TYPE="text/javascript">
<!--
myPopup = '';

function popup(mylink, windowname) {
myPopup = window.open(mylink, windowname, 'width=520, height=290, left=450, top=350, scrollbars=yes');
if (!myPopup.opener)
myPopup.opener = self;
}
//-->
</SCRIPT>

</head>

<body bgcolor ="#c0c0c0" onUnload="myPopup.close()">
..................

Everytime when user leaves this pages (onUnload), there is a popup box showing this:

A Runtime Error has occcured
Do you wish to Debug?

Line: 48
Error: Object doesn't support this property or method

The error points to "myPopup.close()".

The weird thing is it happens only on my boss' browser. Mine doesn't give me any error. I wish it could be the other way around :(

Does anybody know what this error is? Thanks a lot!!

Khalid Ali
11-06-2003, 10:21 AM
this mean that mypopup is not seen as a popup window handle(reference).
using something at onunload is not a very good idea, re think you rlogic.

Jen Song
11-06-2003, 10:34 AM
Thanks. But why only my boss has this problem? I've asked around, nobody else sees this error. Is it because of some kinda browser settings?

And if unUnload is not a good idea, how do I close a popup when the user leaves the main window? Thanks again.

Khalid Ali
11-06-2003, 10:47 AM
thats a possibility, have your boss use the most recent version of the browser,and to close the popup let the user do it themselves,such as by clicking a button.

Jen Song
11-06-2003, 11:01 AM
Thanks Khalid. I do provide a close button in my popup window. If the user wasn't lazy enough to click on that, I wouldn't get into this whole trouble at all :) What they want is that if they happen to forget this popup is still open and leave the main window, the popup will feel too bad to stay there anymore and close itself.

ShinCat
11-06-2003, 11:06 AM
Hi, I just started learning javascript about a month ago so please pardon me if I'm about to make a mistake. Using Mozilla 1.4, I received a similar error. The software was rewritten as follows and the error went away.

var overviewWin;

function openOverviewWin()
{
if( !overviewWin || overviewWin.closed )
{
overviewWin = open('overview.htm','overviewWindow', 'height=540, width=580, left=128, top=32');
}
else
{
overviewWin.focus();
}
}

Moderator, could you please tell me why using "onunload" is a not a good idea? I can only think of one, which is a refresh will kill the popup. I also use the "onunload" event to close a child popup.

Thanks.