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.
Asked
Active
Viewed 9,128 times
2
-
edited tags as php has nothing to do here – Your Common Sense Jul 07 '10 at 05:59
-
This is difficult. You could do this in JavaScript, but this code would have to have access to the tabs API of the browser and I don't believe (and hope) that JS on websites have these privileges. Of course if you open the new tab *from* the current website then it is easier. But testing whether an other tab already contains the site is difficult. – Felix Kling Jul 07 '10 at 06:01
-
This is possible using javascript, i have answered for the same. Please check it.. – Kanak Vaghela Jul 07 '10 at 06:06
3 Answers
3
Use this script
<html>
<head>
<script type="text/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();
}
function newwin (urllink) {
newwindow = window.open( urllink ,'newwin')
}
</script>
</head>
<body>
<a href="javascript:newwin('http://www.bbc.co.uk')">bbc</a><br>
<a href="javascript:newwin('http://www.google.co.uk')">google</a>
<form>
<input type="button" value="close me!!" onClick="close1()"/>
<input type="button" value="Close" onClick="window.newwindow.close()">
<form>
</body>
</html>

elemjay19
- 1,126
- 3
- 25
- 51

Kanak Vaghela
- 7,750
- 10
- 32
- 37
-
Learn how to format code - just select it and click the editor image with the 010101. – Oded Jul 07 '10 at 06:02
1
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>

Matt Mitchell
- 40,943
- 35
- 118
- 185
0
Please try this
<script type="text/javascript">
function newwin (urllink) {
newwindow = window.open( urllink ,'newwin')
}
</script>