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 the href so i did it. You can also add this in onclick="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
Add a ment  | 

3 Answers 3

Reset to default 3

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:

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