javascript - window.close() 在 Jquery 模态中不起作用

标签 javascript jquery

我正在尝试使用对话框模式在我的网页上显示条款和条件。但在按钮上不同意,在调用函数 window.close 时,网页不会关闭。
我想在单击不同意按钮后关闭最近的页面
下面粘贴的是我遇到问题的示例代码。

<script>
  $(function() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:600,
      width:400,
      modal: true,
      buttons: {
        'Agree': function() {
          $( this ).dialog( window.location.assign('../mdv/main.php') );
        },
        'Disagree': function() {
          $( this ).dialog( window.close() );
        }
      }
    });
  });
  </script>


提前谢谢您。

最佳答案

你这样做:

<script>
  $(function() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:600,
      width:400,
      modal: true,
      buttons: {
        'Agree': function() {
          $( this ).dialog( window.location.assign('../mdv/main.php') );
        },
        'Disagree': function() {
          $( this ).dialog("close");
        }
      }
    });
  });
  </script>

您可以使用上面的代码关闭对话框本身,或者如果它是之前通过 JavaScript 打开的弹出窗口,则可以关闭该窗口。 在这种情况下,您将需要该引用来调用 close 方法。

但是,您无法使用 JavaScript 关闭整个网页/选项卡,这是 JavaScript 的限制。正如我提到的,只有之前使用 JavaScript 打开过它,您才能将其关闭。

关于javascript - window.close() 在 Jquery 模态中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31749702/

相关文章:

javascript - 基于选择性超时的事件处理 : immediate first, 接下来去抖动

php - 当用户导航到另一个页面时自动开始下载

javascript - 为单个父单击显示/隐藏多个子类(Jquery)

javascript - JQuery Smooth Scroll - 如何不定位一个 anchor 链接?

jquery - 页面滚动技术/过渡-如何

javascript - 关闭打开的子菜单 - jQuery Accordion

java - HighCharts 动画安卓

javascript - 在 html 文档上显示闪烁文本光标

id 上的 jquery 选择器返回 id 属性未定义

javascript - 如何显示进度条直到加载整个 aspx 页面?