Can someone help e debug this popup window script please?

D

Don

Hi,

I have the following script that displays a popup window centered in the
middle of the screen. I am getting a script error in both IE and Netscape
but I don't know what it means. Thanks in advance.

The error is
------------
Error: win has no properties
Line 13 below ( win.window.focus(); )

The code is
------------
var win= null;
function newWindow(mypage,myname,w,h,scroll) {
var winl = (screen.availWidth-w)/2;
var wint = (screen.availHeight-h)/2;
var settings ='height='+h+',';
settings +='width='+w+',';
settings +='top='+wint+',';
settings +='left='+winl+',';
settings +='scrollbars='+scroll+',';
settings +='resizable=yes';
win=window.open(mypage,myname,settings);
if(parseInt(navigator.appVersion) >= 4)
win.window.focus();
if (!win.opener)
win.opener = self;
}
 
F

F. Da Costa

Don said:
Hi,

I have the following script that displays a popup window centered in the
middle of the screen. I am getting a script error in both IE and Netscape
but I don't know what it means. Thanks in advance.

The error is
I'm no specialist but the win.window.focus() seems rather odd (to me).
Why not win.focus() (y'v got the variable).
Otherwise I'd set a breakpoint below win=... to see what has happened.

F DCG
 
K

kaeli

Hi,

I have the following script that displays a popup window centered in the
middle of the screen. I am getting a script error in both IE and Netscape
but I don't know what it means. Thanks in advance.

The error is

win is a window object. There is no window property of a window object,
AFAIK.
win=window.open(mypage,myname,settings);
if(parseInt(navigator.appVersion) >= 4)
win.window.focus();

win.focus() or win.document.focus()


--
--
~kaeli~
A little rudeness and disrespect can elevate a meaningless
interaction to a battle of wills and add drama to an
otherwise dull day.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
K

kaeli

The error is
Also, you don't check for null before you try
win=window.open(mypage,myname,settings);
if(parseInt(navigator.appVersion) >= 4)
{
if (win != null)
win.focus();
else alert("no window object");
}
if (!win.opener)
win.opener = self;
}

That would cause problems with popup blockers that killed the window.

--
--
~kaeli~
A little rudeness and disrespect can elevate a meaningless
interaction to a battle of wills and add drama to an
otherwise dull day.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
D

DU

Don said:
Hi,

I have the following script that displays a popup window centered in the
middle of the screen. I am getting a script error in both IE and Netscape
but I don't know what it means. Thanks in advance.

The error is

This message might refer to an asynchronuous state of the window and its
object reference. The win variable might not be created in the stack
while you're trying to access its properties.
The code is
------------
var win= null;
function newWindow(mypage,myname,w,h,scroll) {
var winl = (screen.availWidth-w)/2;
var wint = (screen.availHeight-h)/2;
var settings ='height='+h+',';
settings +='width='+w+',';
settings +='top='+wint+',';
settings +='left='+winl+',';
settings +='scrollbars='+scroll+',';
settings +='resizable=yes';

Scrollbars should be set to true (or 1) at all the time: scrollbar(s)
should appear when content overflows requested window dimensions,
otherwise the popup goes against normal and standard accessibility to
content.
win=window.open(mypage,myname,settings);
if(parseInt(navigator.appVersion) >= 4)
win.window.focus();

There is no point to this instruction. You are supposed to just have
created and opened a new window which will be brought on top of the
opener. Why try to bring it on top? This is redundant and unneeded.
if (!win.opener)
win.opener = self;

This instruction too should be dropped. It can only lead to problems.

DU
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top