tags:

views:

61

answers:

4

I have opened a website in a browser tab. Now, when I open a new tab from this website, I want to close the first tab in that browser.

A: 

You cannot use PHP to close a window but you can use this script

<script language="javascript" type="text/javascript"> 
    function closeWindow() { 
      window.open('','_parent',''); 
      window.close(); 
    } 
</script> 

First Source

Second Similar Demo

Graphain
+2  A: 

Hi,

Use this script

<script language="javascript">
function click1()
{
window.open("http://127.0.0.1/");
window.open("http://127.0.0.1/wordpress/?page_id=2");

}
function close1()
{
var c="http://127.0.0.1/";
c.close();
}
</script>
<input type="button" value="close me!!" onClick="close1()"/>-->



<html>
<head>
<script type="text/javascript">
function newwin (urllink) {
newwindow = window.open( urllink ,'newwin')
}
</script>
</head>
<body>
<a href="javascript:newwin('http://www.bbc.co.uk')"&gt;bbc&lt;/a&gt;&lt;br&gt;
<a href="javascript:newwin('http://www.google.co.uk')"&gt;google&lt;/a&gt;
<form>
<input type="button" value="Close" onClick="window.newwindow.close()">
<form>
</body>
</html>
Kanak Vaghela
Learn how to format code - just select it and click the editor image with the 010101.
Oded
On the `close1` function, `c.close` will not work, `c` is simply a string...
CMS
+1  A: 

Hello,

I have this type of script. so try it. i hope it will help for you.

http://www.gtalbot.org/BrowserBugsSection/MSIE6Bugs/ClosingWindowsNotOpenedByJS.html

Thanks

How is this the correct answer to the question? How do you know when a user opened a new tab?
Konerak
A: 

Hello, Please try this

<script type="text/javascript">
function newwin (urllink) {
newwindow = window.open( urllink ,'newwin')
}
</script>
Kanji