2

I'm trying to close another window when I'm clicking on a specific link. (with javascript)

I have only find a solution where I can close the current window I'm in.

I'm in shop.php and want to close client.php

So when I'm click on the shop.php I will close client.php..

<li class="viptab"><a href="{url}/shop" target="_blank" onClick="javascript:window.close('client.php')">SHOP</a><span></span></li>

Any suggestions?

2
  • Did JavaScript open up the window? AKA window.open() Commented Sep 5, 2014 at 13:20
  • Yes, it did. Opened shop and client at the same time. Commented Sep 5, 2014 at 13:24

1 Answer 1

3

Use if you want close current window . <button onclick="self.close()">Close </button>

Or use this if you want close child window from parent

<!DOCTYPE html>
<html>
<body>

<button onclick="openWin()">Open </button>
<button onclick="closeWin()">Close </button>

<script>
var myWindow;

function openWin() {
    myWindow = window.open("/client.php", "_blank", "width=500, height=500");
}

function closeWin() {
    myWindow.close();
}
</script>

</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.