Thursday 16 May 2013

How to close current tab in a browser window


<script type="text/javascript">
function closeWin()
{
var win = window.open('','_self'); /* url = "" or "about:blank"; target="_self" */
win.close();
}
</script>

<input type="button" name="CloseWin" value="CloseWin" onclick="closeWin();" ></input>
<!-------------------------------------------------------------->
<script type="text/javascript">
function close_window() {
  if (confirm("Close Window?")) {
    close();
  }
}
</script>
<a href="javascript:close_window();">close</a>
<a href="#" onclick="close_window();return false;">close</a>

<!-------------------------------------------------------------->

<script>
    function closeWindow() {
        window.open('','_parent','');
        window.close();
    }
</script>

<a href="javascript:closeWindow();">Close Window</a>

<!-------------------------------------------------------------->

<a href="blablabla" onclick="setTimeout(function(){var ww = window.open(window.location, '_self'); ww.close(); }, 1000);">
    If you click on this the window will be closed after 1000ms
</a>

No comments:

Post a Comment