使用 JavaScript/Jquery 关闭 .aspx

close .aspx using JavaScript/ Jquery

我在
window.close and self.close do not close the window in Chrome 等其他链接上搜索过这个问题,但无法解决
我想使用以下代码关闭页面,但它在任何浏览器上都不起作用。

我的 url 就像:

http://server/solutionName/Confirmation.aspx

警告

Scripts may close only the windows that were opened by it.

HTML:

 <img alt="Close" src="images/close.png" onclick="return confirm_delete();">

脚本

  function confirm_delete()
   {
      if (confirm("Are you sure you want to close?") == true)
          window.close();

      else
          return false;
    } 


这是屏幕截图:

Chrome 的 hacky 解决方法(在其内部重新打开 window 并关闭它):

<script>
    open(location, '_self').close();
</script>

此代码适用于我的 Chrome:

<script>

function confirm_delete()
{
    if (confirm("Are you sure you want to close?") == true) open(location, '_self').close();
    else return false;
} 
confirm_delete();

</script>

window.close When this method is called, the referenced window is closed.

This method is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.

https://developer.mozilla.org/en-US/docs/Web/API/Window.close

尝试以下代码行

        var Browser = navigator.appName;
        var indexB = Browser.indexOf('Explorer');
        if (indexB > 0) {

            var indexV = navigator.userAgent.indexOf('MSIE') + 5;
            var Version = navigator.userAgent.substring(indexV, indexV + 1);

            if (Version >= 7) {
                window.open('', '_self', '');
                window.close();
            }
            else if (Version == 6) {
                window.opener = null;
                window.close();
            }
            else {
                window.opener = '';
                window.close();
            }
        }
        else {
            window.close();
        }