admin管理员组文章数量:1406175
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
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
Share Improve this question asked May 25, 2016 at 3:37 aron pascuaaron pascua 1112 silver badges10 bronze badges 4-
Try this
<a href="javascript:window.close();">Close Window</a>
– Murad Hasan Commented May 25, 2016 at 3:41 - where can I add my href='review.php?id=$col1' – aron pascua Commented May 25, 2016 at 3:47
-
1
you are asking to add the
window.close
at thehref
so i did it. You can also add this inonclick="javascript:window.close();"
– Murad Hasan Commented May 25, 2016 at 3:52 - but how can I add the code to direct to the next page. What im really trying to do is, when I click the button to the next page, the first page will close – aron pascua Commented May 25, 2016 at 3:55
3 Answers
Reset to default 3I 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>';
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.
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." target="_blank" onClick="javascript: setTimeout(window.close, 10);">Close Me</a>
本文标签: javascriptHow can I use the windowclose() inside a hrefStack Overflow
版权声明:本文标题:javascript - How can I use the window.close() inside a href? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744343452a2601616.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论