Web Hosting Talk







View Full Version : Javascript close window + refres(reload) window


Syncedit
12-29-2002, 01:12 PM
For my site a use an session login, to login you first must click on a link which opens a popup window.

If you are logged in the popup window shows "you are now logged in hmm :)" and

<form><input type=button value=' Close window ' onClick='javascript:window.close();'></form>

to close the window


But on the original page it stays "You are logged out, click here to log in (popup again", if you refresh the status changes to logged in.. correct

but I'm looking for some javascript code to close the popup window and to refresh or reload the original window so that the status changes to "you are logged in"

But i don't know to give the original window a name, and how to combine those 2 javascript codes,


thx!

cedric

Saeven
12-29-2002, 06:42 PM
The way you'd usually want to handle these things is as follows:

1. Your link on main page adjusts whether or not the person is logged in.

- If the user is not logged in, a link to a login page appears.

- If the user is logged in, you'd display (logged in) or something simliar.

2. Your login page contains a form with username and password and whatever else.

Let $_SESSION['user'] be your session variable with the user's name or email or what have you.

This would be your link builder on your main page:


if( !isset( $_SESSION['user'] ) )
echo '<a href="#" onClick="MyWindow=window.open(\'login.php\',\'Login\', \'toolbar=no,location=no,directories=no,status=no,'.
'menubar=no,scrollbars=no,resizable=yes,width=300,height=175,left=100,top=50\'); return false;">log in</a>';
else
echo 'logged in';


Now, your login page will contain a form that checks against user name and password or whatever, if the login is sucessful, this is what it does:


echo '<script>window.opener.location.href=\YOURINDEXPAGE.php</script>';
echo '<script>window.close()</script>';


That's it!

Syncedit
12-30-2002, 03:13 PM
worked great,

thx!