简体   繁体   English

如何在href内使用window.close()?

[英]How can I use the window.close() inside a href?

How can I use window.close() inside 我如何在里面使用window.close()

Im trying to add the window.close() inside my href. 我试图在我的href中添加window.close()。 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 我试图在这一行中添加window.close()

echo "<th><a target='_blank' href='review.php?id=$col1'>Click</a></th>";

i hope someone can help. 我希望有人能帮帮忙。 thank you 谢谢

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>';

You can call a function onclick button: 您可以调用函数onclick按钮:

function close_window() {
  if (confirm("Close Window?")) {
    close();
  }
}

If you want to use only html then you can do this: 如果您只想使用html,则可以执行以下操作:

<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. 为了避免事件的默认行为,使用return false The browser will attempt to open that URL otherwise. 浏览器将尝试否则打开该URL。

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. 由于您要打开一个新的选项卡/窗口并关闭当前选项卡/窗口,因此您将要为window.close函数启动超时。

HTML 的HTML

<a href="http://www.google.com" target="_blank" onClick="javascript: setTimeout(window.close, 10);">Close Me</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM