Click to See Complete Forum and Search --> : check whether child window is open from parent window - urgent


Ramachandran
03-13-2003, 11:33 AM
Hi,

I have a intranet Application which uses a security system for authentication.

My requirement is that when a user logs into the application there will be link shown to the application.If the user clicks the link a window is opened which will be closed by the application developers and they will open a new window. which is the welcome page where the user can choose country and language.

Now if another user logs(using new browser instance IE) he will also see the application link and if he clicks the application ,at that time i have to check whether already a welcome page is opened ,if so i have to alert him saying that already a user has logged in and ask him to logout,otherwise if he is the first user and there is no welcome page open already then i should allow him to proceed as normally.

What i want to know is that how do i check whether the window (welcome page) is already open or not from the first window which i close say the file is index.html(opened first).

Hope my question is clear.Kindly reply as soon as possible

Thanks
Rama

khalidali63
03-13-2003, 11:43 AM
say childwindows name is

newWin;

then yo will do this

if(newWin.closed){

}

Khalid

Ramachandran
03-13-2003, 09:37 PM
Hi Dave,

The first html which will be called is index.html and in that html i open a new window(welcome page) and also close this index.html.

So the code u have given has to be there in index.html or welcome page.I think it should be there in index.html.

can u clarify this and also let me know how the object that is created is checked like this if (!winPtr.MyWelcomePage).


Thanks
Rama

Ramachandran
03-14-2003, 01:08 AM
Hi Dave,

The following is the code i have in index.html which will be opened first.

<html>
<head>
<title>Welcome to Credit Decision Parameter Maintenance</title>
<!--LINK REL="StyleSheet" HREF="../js/style.css" type="text/css"-->
<script language="javascript">
var winName=null;
function callwindow()
{
/*if(winName)
{
winName.close();
alert("inside code");
alert("Already a user has logged in,kindly log out");
}*/
welcomepage = new Object();
winName=window.open('/weblogic/MaintControllerServlet?pgm_name=home','CD','menubar=no,toolbar=no,status=yes,locationbar=no,maximize =no,resizable=no,border=thin,width=790,height=550,top=0,left=0');
if(!winName.welcomepage)
{
//winName.close();
}
else
alert("Already Logged in");
}


</script>
</head>
<body onLoad="callwindow();window.close()">
</body>
</html>



In the above code in body tag I close this window and i open another window which is welcome.jsp througha url(I contact servlet with some parameter which opens welcome.jsp).

So if the first user come in index.html will be opened which will be closed and welcome page will be opened.

So if the second user comes througha fresh browser instance and clicks the application similar process will happen,but i want to check whether welcome page of first user exists,if it is open i will not allow the second user to proceed and i have to alert him that already a user has logged in.

My doubt is that both being seperate browser instances how it is possible.

Is it possible to add your code in index.html and show me the code.


Rama

Ramachandran
03-14-2003, 10:56 PM
Hi Dave,

Can u just edit index.html and also tell me what is the use of declaring a object in welcome page when i am going to check whether a window is open or closed in my parent window that is index.html.Only from index.html file i am opening the welcome page.

I am still not comfortable with what code i have to put in index.html and what code i will put in welcome page to achieve the functionality.



Rama

Ramachandran
03-14-2003, 11:32 PM
Hi Dave,

just tell me whether i have understood properly.The below code

winPtr = window.open("", "welcome", "features");

which u have said should be there in index.html should be added or i have already a statement opening a new window for welcome.jsp that should be put here.

I am referring to the line

winName=window.open('/weblogic/MaintControllerServlet? pgm_name=home','CD','menubar=no,toolbar=no,status=
yes,locationbar=no,maximize=no,resizable=no,border
=thin,width=790,height=550,top=0,left=0');

What about the above code which opens the welcome page.Where it should be put it.

rRama

Ramachandran
03-14-2003, 11:54 PM
Hi dave,

So following is the index.html.I have done the changes and as u said i will have a object in the welcome page.

<html>
<head>
<title>Welcome to Credit Decision Parameter Maintenance</title>
<!--LINK REL="StyleSheet" HREF="../js/style.css" type="text/css"-->
<script language="javascript">
var winName=null;
function callwindow()
{
var features ='width=790,height=550,top=0,left=0,status=yes,border=thin';

winName=window.open('/weblogic/MaintControllerServlet? pgm_name=home','CD',features);

if(!winName.welcomepage)
{
winName.close();
}
else
alert("Already Logged in");
}


</script>
</head>
<body onLoad="callwindow();window.close()">
</body>
</html>

so is the above code ok or any mistake is there.One more thing the above code will only close the window of the second user and not the window of the first user right if it is already open.

Thanks
Rama

Ramachandran
03-15-2003, 12:02 AM
Hi Dave,

how the object declared in welcome page is accessible in the index.html which is the parent window and how do you say that it identifies the contect of the welcome page.

Can u clarify on this,on how the object helps to identify whether the welcome page is open or not.


Rama

Ramachandran
03-15-2003, 12:23 AM
Hi Dave,

Finally i have understood that the blank window will then be painted with the contents of the last window.open method and when the second user comes only one window will be there and since it is the welcomw page the alert will be fired.

I think i have got it.Thanks for all the effor taken in explaining and i will get back to u after executing the code.


Rama

Ramachandran
03-15-2003, 12:28 AM
I think the second piece of code is tuned finer than the first.Thanks for all the help.Have a nice day.


Rama

Ramachandran
03-17-2003, 02:33 AM
Hi Dave,

I have tested the code and it is working fine,but there is one more problem.

If a user has logged in and there is a welcome page open for him,and if the same user clicks the application link again,the alert already logged in comes assuming to be a diffrent user,but in this case it is the same user.

Can it be avoided if the same user clicks the application link when there is already a welcome page opened by him exists.


Rama

Ramachandran
03-17-2003, 10:05 AM
Hi Dave,

I dont know how to create cookies and access them.

Is it possible for u to show me how to create a cookie example in the welcome page itself and check it in the index.html

So that when the same user cicks on the application link i can give an alert.


Rama

Ramachandran
03-17-2003, 09:25 PM
I dont want to use the easier method of because,since i am getting the username from session everytime and then assigning it to the object and the value may get changed everytime as the same home page will used and the session value will be overwritten by the latest user user who has logged in.

Am i right or we can do this way itself and also the object will be null everytime when the welcome page is refreshed