0

this is my code working fine on localhost but not working on live donn't why

<script language="javascript" type="text/javascript"> 
function closeWindow() { 
window.open('','_parent',''); 
window.close(); 
} 
</script>
<a href="javascript:closeWindow();">Close Tab</a>

Tried this also

<script>
  function Exit() {
     var x=confirm('Are You sure want to Close Tab');
     if(x) window.close();
   }
</script>

<button name='closeIt' onClick="Exit()" >CLICK </Button>

please help

clinton3141
  • 4,751
  • 3
  • 33
  • 46

2 Answers2

0

Simple ask confirmation if it's true then continue to next action and if it's false nothing to do action it's stay the same page

function Exit(){
           var retVal = confirm("Do you want to continue ?");
           if( retVal == true ){
              document.write ("User wants to continue!");
              return true;
           }
           else{
              document.write ("User does not want to continue!");
              return false;
           }
        }

i hope it's work

Sujal Patel
  • 2,444
  • 1
  • 19
  • 38
  • There should be no "try" or "hope" about it. Either your code works or it doesn't. Please test it to be sure. Please explain what your code is doing so that it can be useful to people who want to learn. – clinton3141 Jan 13 '17 at 06:46
  • Simple ask confirmation if it's true then continue to next action and if it's false nothing to do action it's stay the same page – Sujal Patel Jan 13 '17 at 06:48
  • Scripts may close only the windows that were opened by it. it display this not not closing the tab –  Jan 13 '17 at 06:56
  • @SujalPatel great! Put that in the answer. – clinton3141 Jan 13 '17 at 07:06
  • Close i tried various solution nothing works on live Scripts may close only the windows that were opened by it. this displays on console –  Jan 13 '17 at 07:35
  • @SujalPatel please help –  Jan 13 '17 at 10:08
0

Try this:

var win = window.open("about:blank", "_self");
win.close();
Sujal Patel
  • 2,444
  • 1
  • 19
  • 38
  • on click it display about:blank not closing the tab –  Jan 13 '17 at 10:32
  • and var win = window.open("", "_self"); display error Scripts may close only the windows that were opened by it. –  Jan 13 '17 at 10:37
  • 1
    I searched for many pages of the web through of the Google and here on the Stack Overflow, but nothing suggested resolved my problem. After many attempts and "kicks" I changed my way of to test that controller. Then I have discovered that the problem occurs always which I reopened the page through of the Ctrl + Shift + T shortcut in Chrome. So the page was run, but without a parent window reference, and because this can't be closed. – Sujal Patel Jan 13 '17 at 10:44
  • http://stackoverflow.com/questions/25937212/window-close-doesnt-work-scripts-may-close-only-the-windows-that-were-opene – Sujal Patel Jan 13 '17 at 10:44
  • directly you cannot close the window sry. – Sujal Patel Jan 13 '17 at 10:45