开发者

how to open another window and close the window that calls it

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 ano开发者_Python百科ther 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


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> 


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜