tags:

views:

69

answers:

3

I have this code in userpage.php:

<script langauge="JavaScript"><!--
function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); }
//--></script>

<a href="javascript:newWindow('1.html','window1')">Logout</a>

And this code at index.php:

<script language="JavaScript"><!--
function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); }
function replaceURL(fileName) { newWindow(fileName,'window2'); self.close(); }
//--></script>

What Im trying to do is to call another window that show index.php. Calling it with the userpage.php. But the script doesn't close the window that calls it.

Its a logout link. Because when I press back button after logging out. I end up seeing the page which only the user that has logged in can access

A: 

Use window.opener.close(); to close the parent window from the child.

Kangkan
doesn't work: <td><A href="javascript: window.opener.close();">Close </A></td> tried it on firefox and chrome, no luck
A: 

can also use

Following is an example on how to use

lets say the follwing is my html content for Page 1

<html>
<body>

<script type="text/javascript">
myWindow=window.open('2.htm','','width=200,height=100')
myWindow.focus()
</script>

</body>
</html> 

Following is the content for second page 2.htm

<html>
<body>

<script type="text/javascript">

// this will colse the parent window.

window.opener.close();

</script>
Hi hello
</body>
</html> 
Phani Kumar PV
do I put this on the child tab?What would be the code if I want the parent tab to close when the child loads
added the sample code to the post
Phani Kumar PV
A: 

you can't close windows that you didn't open with a script (not in all browsers anyway). so if the parent window is one opened by the user (by firing up a new tab, or opening his browser from the start menu/dock/whatever), you shouldn't be able to close that.

matei
its the script that opened the newtab for me. But why the hell does the parent tab still don't close when I use this: <td><a href="index.html" onclick="window.open('index.html');window.close();return false;" target="newwindow">Logouts</a></td>
that's exactly what I was saying. you can close only windows that you open. you can't open a new window and close the old one if you didn't open the old one by script. In your example, the window in which the <a> is found is probably not opened from a script (with window.open) but open by the user (by opening a browser window himself from the start menu, or CTRL+T or something) , so you are not able to close it from script
matei