下面是我调用servlet的代码,该servlet使用户会话无效并关闭浏览器选项卡。在IE中,浏览器要求用户确认关闭选项卡。在Chrome中,它抛出了一个错误,写着Scripts may close only the windows that were opened by it
。我写这段代码是基于对stackoverflow上类似问题的反馈。有没有一种方法可以调用我的注销servlet,并在随后单击注销时关闭浏览器选项卡,而不要求用户确认。
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#mybutton").click(function(){
$.get("/logoutServlet", function(data, status){
// alert("Data: " + data + "\nStatus: " + status);
});
window.open('','_self').close();
});
});
</script>
</head>
<body>
<button id="mybutton">Logout</button>
</body>
</html>
发布于 2016-10-22 02:16:51
你根本不能,但你能做的是将用户重定向到一个空白页面。
window.location.href = "about:blank";
https://stackoverflow.com/questions/40182608
复制相似问题