954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

javascript know whether a window is opened or not

Hi

I am doing a chating application.I want to know whether a window is opened or not.
This is the code i am using to open a window.

var title='Chat_'+userId+"_"+selectedUserId;

var url="OneToOneChat.aspx?FromUserId="+userId+"&FromUserName="+userName+"&ToUserId="+selectedUserId+"&ToUserName="+selectedUserName;

                window.open(url,title,'width=410,height=400,toolbar=no,menubar=no,scrollbars=no,status=yes',false);


later i trying whether the window is already opened or not.

var win='Chat_'+userId+"_"+selectedUserId;
if(win.closed)
{
}
else
{
}

for win.closed it is giving javascript error like "closed is null or not an object".

I am using IE7.

Please h on this.

Thanks in Advance

Venki

urvenkatg
Newbie Poster
1 post since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Hi,
You might want to try (window.opener.closed)

Thanks.

ankitjain_dce
Newbie Poster
11 posts since Jun 2009
Reputation Points: 10
Solved Threads: 1
 

Oh i think problem might be u r opening the window w/o assigning it to a variable.....fifth line above should be:
var win=window.open(url,title,'width=410,height=400,toolbar=no,menubar=no,scrollbars=no,status=yes',false);

There is no need for new win var in the second javascript code and u can directly for win.closed.

ankitjain_dce
Newbie Poster
11 posts since Jun 2009
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You