How i can close the current window 2 sec after a link with an href _blank is clicked .
<a href="https://google.com" target="_blank"></a>
How i can close the current window 2 sec after a link with an href _blank is clicked .
<a href="https://google.com" target="_blank"></a>
Maybe you can handle click event and from that open window and taking the reference of opened window and close it after timeout.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<button onclick="openWin()">Open Window</button>
</body>
<script>
var myWindow;
function openWin() {
myWindow = window.open("http://www.google.com", "myWindow", "width=200,height=100");
setTimeout(closeWin, 2000)
}
function closeWin() {
myWindow.close();
}
</script>
</html>
The window which has the link can not be closed by Javascript.
only the window which is opened by a script can be closed by that script.
so because your window with the link is not opened by a script, so it can not be closed by a script.
but there are people suggesting some hacky ways. check the following link:
How can I close a browser window without receiving the "Do you want to close this window" prompt?
the problem with hacks is that its not guaranteed to work always on all browser.