Imagine two pages, a.php
and b.php
.
b.php
is the same in both examples:
<script>window.close();</script>
This example HTML will NOT work (a.php
):
<a href="b.php">open b.php</a>
Now, this will work (a.php
again):
<a href="#" onclick="window.open('b.php');return false">open b.php</a>
The reason why. Because Javascript (should) only be able to close a window that it has opened.
The first example HTML is a standard a href
link. No Javascript used.
In the second example, a browser window is opened with Javascript, which can then be closed by Javascript.
PHP is a sever side script and has nothing to do with it at all. Would be best if the PHP tag was removed from the question.