gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:23:49 25 4
gpt4 key购买 nike

我正在尝试使用对话框模式在我的网页上显示条款和条件。但在按钮上不同意,在调用函数 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com