Reputation: 111
How can I use window.close() inside
Im trying to add the window.close() inside my href. This is my code for that matter
while(mysqli_stmt_fetch($stmt)) {
echo "<tr>";
echo "<th>".sprintf("%s", $col2)."</th>";
echo "<th>".sprintf("%s", $col3)."</th>";
echo "<th>".sprintf("%s", $col4)."</th>";
echo "<th>".sprintf("%s", $col18)."</th>";
echo "<th>".sprintf("%s", $col19)."</th>";
echo "<th><a target='_blank' href='review.php?id=$col1'>Click</a></th>";
echo '</tr>';
}
im trying to add the window.close() in this line
echo "<th><a target='_blank' href='review.php?id=$col1'>Click</a></th>";
i hope someone can help. thank you
Upvotes: 3
Views: 8962
Reputation: 836
You can call a function onclick button:
function close_window() {
if (confirm("Close Window?")) {
close();
}
}
If you want to use only html then you can do this:
<a href="javascript:close_window();">close</a>
or
<a href="#" onclick="close_window();return false;">close</a>
To avert the default behavior for the event return false
is used. The browser will attempt to open that URL otherwise.
Upvotes: 1
Reputation: 390
Since you are wanting to open a new tab/window and close the current one, you will want to start a timeout for the window.close function.
HTML
<a href="http://www.google.com" target="_blank" onClick="javascript: setTimeout(window.close, 10);">Close Me</a>
Upvotes: 0
Reputation: 9583
I think you are looking for this.
<a href="javascript:window.close();">Close Window</a>
In your case:
echo '<th><a target="_blank" href="javascript:window.close();">Click</a></th>';
Upvotes: 3